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

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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://454452]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (10)
As of 2018-03-20 21:51 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (259 votes). Check out past polls.