Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re^3: foreach doesn't select array element

by Marshall (Canon)
on May 04, 2009 at 10:08 UTC ( #761688=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 (@$fldref3) {} automatically use the referenced array or spit out a warning about passing a single ref?

I didn't read your code in detail, but when de-referencing a subscript'ed thing, you need to use {} to show "@" what it is operating upon, eg.. @{$fldref[3]}. If $fldref is just a single ref, then @$fldref works. But this doesn't work if $fldref has a subscript.

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

    Aha. So perhaps I expected the @ in @$fldref[] to operate on the whole thing, whereas I need the @{} to point out the subscript should be on the inside to (de)refer to the right array...

    I admit I don't always immediately understand in complex variable statements which @{(@$var[3])->[0]}[3] subscript applies to which part... At one point 2 3 4 levels deep with one single ref, the whole operator precedence becomes a bit confusing.

    Thanks for the help.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2023-05-28 02:59 GMT
Find Nodes?
    Voting Booth?

    No recent polls found