Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Function templates done right

by vladb (Vicar)
on Feb 14, 2002 at 19:49 UTC ( [id://145540]=note: print w/replies, xml ) Need Help??


in reply to Function templates done right

This worked for me:
use strict; sub foo { print "inside main foo ($_[0])\n"; } sub bar { print "inside main bar ($_[0])\n"; } foreach my $sub (qw(foo bar)) { $main::{$sub}->($sub); }
OUTPUT:
-----
 inside main foo (foo)
inside main bar (bar)
-----


In case of $self->SUPER::$funcName(@_), I guess you could try $self->SUPER{$funcName}->(@_)?

The trick is you can't just write something like $main::$sub_name(), but have to go the $main::{$sub}->(@args) way instead. This works since $main::{$sub} would return a typeglob for the name '$sub', and when you apply () operator to that typeglob, appropriate subroutine will be invoked.


"There is no system but GNU, and Linux is one of its kernels." -- Confession of Faith

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-04-19 16:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found