Closed p5pRT closed 14 years ago
Why does the first @{$u} cause a warning (with -w) but the second one doesn't?
$u = undef; @w = @{$u}; for (@{$u}) {};
Use of uninitialized value in array dereference at - line 3.
Seen in perl-current (rc1 to be) and all the way back to 5.005_03\, although the warning may vary.
I started tracking this down (but the email client crashed with an hour worth of notes in it.) I think it's got something to do with the second pp_rv2av op having the OPf_REF flag set\, but the first one doesn't\, probably because of what the for is going to do with it. I tried to track down where it got set\, but it was a twisty twisty maze.
-R (mentioning perl for the bugtron.)
Same result on 5.12.0.
On Thu Apr 18 15:12:26 2002\, rspier@pobox.com wrote:
Why does the first @{$u} cause a warning (with -w) but the second one doesn't?
$u = undef; @w = @{$u}; for (@{$u}) {};
Use of uninitialized value in array dereference at - line 3.
Seen in perl-current (rc1 to be) and all the way back to 5.005_03\, although the warning may vary.
I started tracking this down (but the email client crashed with an hour worth of notes in it.) I think it's got something to do with the second pp_rv2av op having the OPf_REF flag set\, but the first one doesn't\, probably because of what the for is going to do with it. I tried to track down where it got set\, but it was a twisty twisty maze.
-- Alexandr Ciornii\, http://chorny.net
Same result on 5.12.0.
On Thu Apr 18 15:12:26 2002\, rspier@pobox.com wrote:
Why does the first @{$u} cause a warning (with -w) but the second one doesn't?
$u = undef; @w = @{$u}; for (@{$u}) {};
Use of uninitialized value in array dereference at - line 3.
Seen in perl-current (rc1 to be) and all the way back to 5.005_03\, although the warning may vary.
I started tracking this down (but the email client crashed with an hour worth of notes in it.) I think it's got something to do with the second pp_rv2av op having the OPf_REF flag set\, but the first one doesn't\, probably because of what the for is going to do with it. I tried to track down where it got set\, but it was a twisty twisty maze.
-- Alexandr Ciornii\, http://chorny.net
On Thu Apr 18 15:12:26 2002\, rspier@pobox.com wrote:
Why does the first @{$u} cause a warning (with -w) but the second one doesn't?
$u = undef; @w = @{$u}; for (@{$u}) {};
When an undefined variable is used in an lvalue deference\, Perl creates the required variable and reference. This is called autovivification.
The first dereference is not an lvalue\, so it warns when the expected reference is missing.
perl -wle"my @w=@$u; print $u // '[undef]';" Use of uninitialized value $u in array dereference at -e line 1. [undef]
The second dereference is an lvalue\, so Perl autovivifies $u instead of warning.
perl -wle"1 for @$u; print $u // '[undef]';" ARRAY(0x248b54)
If you wish to change the behaviour of Perl with respect to autovivification\, use the "autovivification" module on CPAN.
Since lvalue-ness of foreach elements and autovivification are both intentional features\, I'm closing this ticket.
@ikegami - Status changed from 'open' to 'rejected'
Migrated from rt.perl.org#8955 (status was 'rejected')
Searchable as RT8955$