You're right about the mistake, except that what grep returns is already a hashref so by adding [ ] around it, you make an array of array
You can just provide a list context to the expression with ($usefulans,) (the comma is optional, but I put it there to show that the parenthesis is there to force list context), which will put the first result into $usefulans and drop the others. But since there should be only one match ...
b R interrupt$VAR1 = [ [ 'a', 'W', 'interupt' ], [ 'b', 'R', 'interrupt' ], [ 'c', + + + 'W', + + + 'innterupt' + + + ], + + + [ + + + 'd', + + + 'W', + + + 'intterupt' + + + ] + + + ]; + + + ($answer,) = grep { $$_[0] eq 'b' } @$VAR1; + + + print "@$answer";
But oakb, you should consider a hash (with answer id as the key). You could easily turn your array into one with : %hash = map { shift @$_ => $_ } @$qablock Then you'd just have to do $hash{$givenAnswer} to get ['w', 'interupt']
In reply to Re^2: grep and dereferencing an array of arrays
by Eily
in thread grep and dereferencing an array of arrays
by oakb
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |