and here is the code that does the magic:my $first_stuff = first_value {$_ > 2} 1..10;
Notice, how you localize the elements of the array one by one, so that you can refer to them as $_ in your code.sub first_value (&@) { my $test = shift; local $_; foreach (@_) { return $_ if $test->(); } return undef; }
I do not really know, how could you achieve similar effects without using our, if you can at all, but I am not entirely sure...
In reply to Re: Examples fo Where "our" is really needed
by rg0now
in thread Examples fo Where "our" is really needed
by geekondemand
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |