Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Examples fo Where "our" is really needed

by rg0now (Chaplain)
on May 05, 2005 at 18:02 UTC ( #454452=note: print w/ replies, xml ) Need Help??


in reply to Examples fo Where "our" is really needed

Please, ignore this node, I wrote it before actually thinking. I am stupid...

I think a pretty nice use of our is to localize $_. So, for example, with List::MoreUtil you can write code like this:
my $first_stuff = first_value {$_ > 2} 1..10;
and here is the code that does the magic:
sub first_value (&@) { my $test = shift; local $_; foreach (@_) { return $_ if $test->(); } return undef; }
Notice, how you localize the elements of the array one by one, so that you can refer to them as $_ in your code.

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...


Comment on Re: Examples fo Where "our" is really needed
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://454452]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2014-12-29 07:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (185 votes), past polls