Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
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...

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 about the Monastery: (6)
As of 2016-10-01 18:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?






    Results (3 votes). Check out past polls.