in reply to Re^4: Data structure / hash reference question
in thread Data structure / hash reference question
I was curious as to how this could work, so I got playing around.
I forgot that you could substitute the -> deref operator for ${}
perl -E '$h={a=>1,b=>2}; say $h->{a}'
...is the same as:
perl -E '$h={a=>1,b=>2}; say ${$h}{a}'
In roboticus' attempt that you pointed out, you'd still need to use the parens inside of the deref block, or else perl will try to use the bareword 'first' as the name of the hash instead of evaluating the expression to its final value (I only found this after testing it):
my $color = ${( first { $class =~ /$_->{'re'}/ } @rules )}{ color };
|
|---|