Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^7: Array dereference in foreach()

by choroba (Cardinal)
on Nov 16, 2017 at 12:23 UTC ( [id://1203584]=note: print w/replies, xml ) Need Help??


in reply to Re^6: Array dereference in foreach()
in thread Array dereference in foreach()

Note that $a gets autovivified into [] after for (@$a) -- that's because for creates a special context similar to lvalue (as its list's elements are aliased to the loop variable).

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^8: Array dereference in foreach()
by pme (Monsignor) on Nov 16, 2017 at 12:55 UTC
    What is this "special context similar to lvalue"? Is there any difference to usual lvalue other than not throwing exception in case of array-dereferencing undef?

    However it is not special enough to work smoothly with dereferencing undef as hashref. This one throws exception.

    my $a; foreach (keys %$a) { print "$_\n"; }
      keys doesn't propagate the outer context to its argument.
      #!/usr/bin/perl use strict; use warnings; my $x; 1 for %$x; print $x, "\n"; # HASH(0x26a18cd)

      ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
        I suspected that based on haukex comment below.

        Thank you guys!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1203584]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-03-28 16:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found