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.
> 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
In reply to Re^4: Subroutine evaluated as boolean (central exit point)
by LanX
in thread Subroutine evaluated as boolean
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |