A lot better, with that @{}...
... but I don't understand why Data::Dumper seems to suggest that @$fldref[3] points to an array, see original post – the fourth field is an array, as there's no slash in front of it. That's probably what confuses me.
Shouldn't foreach (@$fldref[3]) {} automatically use the referenced array or spit out a warning about passing a single ref?
Thanks for the help, though. I think I've been staring at the same code for too long...
| [reply] [d/l] [select] |
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.
| [reply] [d/l] |
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.
| [reply] [d/l] |
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.
| [reply] [d/l] [select] |
[
"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! | [reply] [d/l] |