Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^3: simple anonymous subroutine and variable interpolation timing question

by ikegami (Patriarch)
on Jun 23, 2011 at 21:24 UTC ( [id://911173] : note . print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    my $sub = sub { my ($str) = @_; sub { $str } }->($str);
    
  2. or download this
    my $sub = sub { my $str = $str; sub { $str } }->();
    
  3. or download this
    my $sub = do { my $str = $str; sub { $str } };
    
  4. or download this
    my $str_copy = $str;
    my $sub = sub { $str_copy };
    
  5. or download this
    for my $str (...) {
       ... sub { ... $str ... } ...
    }
    
  6. or download this
    sub make_list_iterator { 
       my @list = @_;
    ...
    }
    
    my $iter = make_list_iterator(@list);