Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re^2: Compare CODE

by tobyink (Abbot)
on Dec 11, 2012 at 14:03 UTC ( #1008306=note: print w/ replies, xml ) Need Help??

in reply to Re: Compare CODE
in thread Compare CODE

The only problem is closed-over variables...

use strict; use warnings; use B::Deparse; sub make_multiplier { my $n = shift; return sub { $n * $_[0] }; } my $double = make_multiplier(2); my $treble = make_multiplier(3); print "double and treble clearly do different things...\n"; print "double 5: ", $double->(5), "\n"; print "treble 5: ", $treble->(5), "\n\n"; my $deparse = B::Deparse->new; $deparse->ambient_pragmas(strict => 'all', warnings => 'all'); print "yet, here is the B::Deparse output for double...\n"; print $deparse->coderef2text($double), "\n\n"; print "and here is the B::Deparse output for treble...\n"; print $deparse->coderef2text($treble), "\n"; __END__ double and treble clearly do different things... double 5: 10 treble 5: 15 yet, here is the B::Deparse output for double... { $n * $_[0]; } and here is the B::Deparse output for treble... { $n * $_[0]; }
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Comment on Re^2: Compare CODE
Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (12)
As of 2016-02-08 17:38 GMT
Find Nodes?
    Voting Booth?

    How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?

    Results (279 votes), past polls