Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: naming anonymous subroutines inner variables

by writch (Sexton)
on Jun 22, 2016 at 20:29 UTC ( [id://1166302]=note: print w/replies, xml ) Need Help??


in reply to Re: naming anonymous subroutines inner variables
in thread naming anonymous subroutines inner variables

Didn't do anything except make the value that fails $self->{$k} instead of $self->{$_}.
  • Comment on Re^2: naming anonymous subroutines inner variables

Replies are listed 'Best First'.
Re^3: naming anonymous subroutines inner variables
by zwon (Abbot) on Jun 22, 2016 at 21:08 UTC
    Works for me:
    #!/usr/bin/env perl use 5.014; use strict; use warnings; my $self; for my $k (qw(foo bar baz)) { $self->{$k} = sub { return join $k, @_ }; $self->{"f_$k"} = sub { my $self = shift; return $self->{$k}->(@_); }; } for my $k (qw(foo bar baz)) { say $self->{"f_$k"}->($self, qw(a b c)); } __END__ afoobfooc abarbbarc abazbbazc
    It would be more productive if you would show something we could actually run.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-25 23:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found