WalruZ has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to dynamically construct a call to an autoloaded function of a class. The class isn't in my control. I can't come up with the right syntax for the line below the comment in the supplied non-functional example. It looks like it does because I have been flailing.
I genuflect.#!/usr/bin/perl use strict; my %vars = ( 'user_login' => { req => 1 }, 'user_passwd' => { req => 1 }, 'user_display' => { req => 0 }, ); my $f = Foo->new(); while ( (my ($key,$atr)) = (each %vars)) { print "$key, $atr\n"; # eg, trying to construct and call autoloaded # $f->prefix_user_login method. &$f->"prefix_$key"( $atr); } package Foo; sub new { return bless( { }, shift); } sub AUTOLOAD { use vars '$AUTOLOAD'; print "autoloaded method: $AUTOLOAD \n"; } sub DESTROY {}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Dynamically constructed function calls
by ikegami (Patriarch) on Nov 03, 2004 at 23:50 UTC | |
|
Re: Dynamically constructed function calls
by itub (Priest) on Nov 03, 2004 at 23:53 UTC | |
by dpuu (Chaplain) on Nov 04, 2004 at 01:07 UTC | |
by ysth (Canon) on Nov 04, 2004 at 02:07 UTC | |
by dragonchild (Archbishop) on Nov 04, 2004 at 04:03 UTC | |
by ikegami (Patriarch) on Nov 04, 2004 at 04:48 UTC | |
| |
by ikegami (Patriarch) on Nov 04, 2004 at 04:37 UTC | |
by itub (Priest) on Nov 04, 2004 at 01:54 UTC | |
|
Re: Dynamically constructed function calls
by BrowserUk (Patriarch) on Nov 03, 2004 at 23:59 UTC | |
|
Re: Dynamically constructed function calls
by Anonymous Monk on Nov 04, 2004 at 12:56 UTC | |
by tall_man (Parson) on Nov 04, 2004 at 15:45 UTC | |
by revdiablo (Prior) on Nov 04, 2004 at 17:47 UTC | |
by dragonchild (Archbishop) on Nov 04, 2004 at 16:44 UTC | |
by BrowserUk (Patriarch) on Nov 04, 2004 at 16:00 UTC | |
| A reply falls below the community's threshold of quality. You may see it by logging in. |