in reply to Re: [ooperl] calling reference to a annonymous sub
in thread [ooperl] calling reference to a annonymous sub

Yes, and elaborating that so it works with an anonymous sub:
#!/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
outputs:
10 10
(The syntax of the final line took me a bit of trial and error to get it right!)

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
    Just a note, generally it's easier and cleaner to use the ->() syntax to call subroutine references, as in your example:  $foo::sub->().