Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^3: foreach doesn't select array element

by AnomalousMonk (Archbishop)
on May 04, 2009 at 10:31 UTC ( [id://761692]=note: print w/replies, xml ) Need Help??


in reply to Re^2: foreach doesn't select array element
in thread foreach doesn't select array element

Shouldn't  foreach (@$fldref[3]) {} automatically use the referenced array or spit out a warning about passing a single ref?
foreach (see perlsyn) will iterate over the list that you build for it. If you build a list by de-referencing a reference to an array (an array which may have zero or one or more elements) or by simply specifying a single scalar (which may be a reference to an array of zero or more elements), that's your business.

Replies are listed 'Best First'.
Re^4: foreach doesn't select array element
by december (Pilgrim) on May 04, 2009 at 13:36 UTC

    But why does Dump show "a", "b", "c", "d" and not \"a", "b", "c", "d"? It seems to show an ordinary array. You don't need to dereference anything in the following basic array:

    [ "anna", "beth", "christie", "denise", ] foreach my $girl (@arr) { print "$girl\n"; }

    ... and if it's a ref to an array instead of an array itself, shouldn't Dump show \... in my original post? It looks as if it's an ordinary by-value array because there's no slash in front of it to point out it's a reference.

    Thanks!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (7)
As of 2024-04-19 09:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found