> return @$_{'VALUE','ADDRESS'} has the same problem as my original code
yeah sorry, I just tested¹ ...
...it's a bit counterintuitive because of the leading @ ... :-/
> @{[@$_{'VALUE','ADDRESS'}]} works great,
better don't combine both techniques, readability is more important!
you could easily do something like
my @ret=();
for ( @$table ) {
next unless $_->{VALUE} eq $wanted;
@ret = @$_{VALUE, ADDRESS}
}
return @ret;
To get a central exit point.
update
> if it is a little confusing to a beginner like me.
the way context is propagated into subs is always confusing, that's why this was changed in Perl6's design!
Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
¹)
DB<116> $_={a=>1,b=>2,c=>3,d=>0}
=> { a => 1, b => 2, c => 3, d => 0 }
DB<117> sub tst { @$_{a,d} }
DB<118> tst()
=> (1, 0)
DB<119> scalar tst()
=> 0
|