Here's a distillation of something that just bit me, behaves the same on
5.6.1 and 5.8.5. Observe the following program:
for (1..2) {
print_file($0);
}
for (qw(one two)) {
print_file($0);
}
sub print_file {
local @ARGV = shift;
while (<>) { print }
}
__END__
Before running it, can you
> "PS" == Peter Scott <[EMAIL PROTECTED]> writes:
PS> Here's a distillation of something that just bit me, behaves the same on
PS> 5.6.1 and 5.8.5. Observe the following program:
PS> for (1..2) {
PS> print_file($0);
PS> }
PS> for (qw(one two)) {
PS> print_file($0);
PS> }
Peter Scott wrote in perl.fwp :
> Here's a distillation of something that just bit me, behaves the same on
> 5.6.1 and 5.8.5. Observe the following program:
>
> for (1..2) {
> print_file($0);
> }
(1..2) constructs a new list of anonymous values. qw(one two), or,
equivalently, (1,2), is just a l
From the keyboard of Peter Scott [13.09.06,09:20]:
> Here's a distillation of something that just bit me, behaves the same on
> 5.6.1 and 5.8.5. Observe the following program:
Try this :-)
$_ = "bar";
print "before the loop: \$_ = $_\n";
for (1..1) {
print "before print_file(): \$_ = $_\n";
From the keyboard of Georg Moritz [15.09.06,01:03]:
> From the keyboard of Peter Scott [13.09.06,09:20]:
>
> > Here's a distillation of something that just bit me, behaves the same on
> > 5.6.1 and 5.8.5. Observe the following program:
>
> Try this :-)
>
> $_ = "bar";
> print "before the loop: \$
On Fri, 15 Sep 2006 01:03:18 +0200, Georg Moritz wrote:
> The error is thrown at the moment the <> oprator tries to assign to $_,
> which is an alias to a constant - the '1'.
>
> Common pitfall ;-)
I know it's a pitfall, I put it in a chapter called "Perl Pitfalls" in my
first book :-) It's just
Peter Scott <[EMAIL PROTECTED]> wrote:
> The documentation is clear that <> doesn't
> localize $_. Why not?
> Just so that if someone wanted to get at the last
> value after the loop they could do it without an extra variable?
With all this talk of local $_, I feel compelled to
point out an insi
John Douglas Porter wrote:
> Peter Scott <[EMAIL PROTECTED]> wrote:
>> The documentation is clear that <> doesn't
>> localize $_. Why not?
>> Just so that if someone wanted to get at the last
>> value after the loop they could do it without an extra variable?
>
> With all this talk of local $_, I
Michael G Schwern wrote:
I have a solution!
DON'T USE $_ [1]
[1] Except in map and grep and the magic while(<>) where its localized.
Didn't this thread start from the fact that $_ is _not_ localized in the
magic while(<>) loop?
--
Ilmari Karonen
> i haven't run it but i already see conflicts with nested $_.
It's not obvious that the $_ nesting is a problem. The point should be moot
because the C loop *should* localize $_. It doesn't. Well, it does,
but there's a loophole.
Quoting pg 18 of the 3rd Edition Camel (emphasis added):
10 matches
Mail list logo