Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
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 surveying the Monastery: (4)
As of 2015-07-04 23:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls