Leser: 1
![]() |
|< 1 ... 3 4 5 6 7 >| | ![]() |
63 Einträge, 7 Seiten |
print "xzy\n" or die "Error: couldn't print: $!\n";
1
2
3
4
5
6
7
8
9
10
sub foo {
local ($_);
while (<>) {
chomp;
print "ich habe $_ gelesen\n";
}
}
foo for $1;
print "ende\n";
QuoteIf you localize a special variable, you'll be giving a new value to it,
but its magic won't go away. That means that all side-effects related
to this magic still work with the localized value.
...
the following snippet will die in perl 5.9.0 :
sub f { local $_ = "foo"; print }
for ($1) {
# now $_ is aliased to $1, thus is magic and readonly
f();
}
...
Notably, if you want to work with a brand new value of the default
scalar $_, and avoid the potential problem listed above about $_ previ-
ously carrying a magic value, you should use "local *_" instead of
"local $_".
1
2
3
4
5
6
sub foo {
"foo" =~ m/(oo)/;
print "foo(@_)";
}
"test" =~ m/(es)/;
foo($1); # gibt 'oo' aus und nicht 'es'
if (my ($elem1, $elem2, @x) = $string =~ /.../ ) {
![]() |
|< 1 ... 3 4 5 6 7 >| | ![]() |
63 Einträge, 7 Seiten |