Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Closures Explained

by pemungkah (Priest)
on Jul 14, 2009 at 19:20 UTC ( [id://780041]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    sub counter {
       my $start_value = shift;
       return sub { return $start_value++; }
    }
    
  2. or download this
    my $counter1 = counter(5);
    my $counter2 = counter(20);
    print $counter1->(), $counter1->(), $counter1->(),"\n";
    print $counter2->(),"\n";
    print $counter1->(),"\n";
    
  3. or download this
    567
    20
    8
    
  4. or download this
    sub build_one {
       my($foo, $bar, $baz) = @_;
    ...
    push @queue, build_one($alpha, $beta, $gamma);
    
    # repeat as necessary.
    
  5. or download this
    map { $_->($last_thing) } @queue;
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2024-04-18 10:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found