in reply to Re: [ooperl] calling reference to a annonymous sub
in thread [ooperl] calling reference to a annonymous sub
outputs:#!/usr/bin/perl #anonysub.pl #use strict; #use warnings; package foo; our $bar = "10\n"; our $anonysub = sub { print "10\n"}; package main; print $foo::bar; &$foo::anonysub(); #before BUU's comment $foo::anonysub->(); #after BUU's comment
(The syntax of the final line took me a bit of trial and error to get it right!)10 10
UPDATE: added another way to do it as BUU suggests below, which, I agree, is cleaner.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: [ooperl] calling reference to a annonymous sub
by BUU (Prior) on Nov 07, 2005 at 10:29 UTC |