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

Re^5: Calling functions from different namespaces

by blazar (Canon)
on Jan 19, 2006 at 08:27 UTC ( #524155=note: print w/replies, xml ) Need Help??

in reply to Re^4: Calling functions from different namespaces
in thread Calling functions from different namespaces

It does work. Well, it should. What are you really trying to do? It's hard to tell without seeing the rest of your code. (also taking into account ikegami's very good suggestion)

# -*- Perl -*- use strict; use warnings; package TT; use base 'Exporter'; our @EXPORT = qw/s1/; sub s1 { my $sub = shift || \&s2; $sub->(qw/foo bar/); } sub s2 { print "Default s2\n"; print "Args: @_\n"; } 1; __END__

#!/usr/bin/perl use strict; use warnings; use TT; # s1 with no args; s1; print "\n"; # s1 with explicit code passed in; s1 sub { local $\="\n"; print "Customized s2"; print "Args:"; print for @_; }; __END__

(Try it yourself!) output:

Default s2 Args: foo bar Customized s2 Args: foo bar

Incidentally, perldoc perlsub and perldoc perlref would help.

Replies are listed 'Best First'.
Re^6: Calling functions from different namespaces
by Anonymous Monk on Jan 19, 2006 at 22:04 UTC
    You got it right. Thanks for all your help. I really appreciate it.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (8)
As of 2018-08-15 16:28 GMT
Find Nodes?
    Voting Booth?
    Asked to put a square peg in a round hole, I would:

    Results (161 votes). Check out past polls.