in reply to [ooperl] calling reference to a annonymous sub

From what I understand about packages, namespaces and scope, you're missing two things:

Hope this helps.

Replies are listed 'Best First'.
Re^2: [ooperl] calling reference to a annonymous sub
by tphyahoo (Vicar) on Nov 07, 2005 at 09:45 UTC
    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.

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