Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: The Dynamic Method Calls Strike Back

by dragonchild (Archbishop)
on Aug 28, 2001 at 02:17 UTC ( [id://108293]=note: print w/replies, xml ) Need Help??


in reply to The Dynamic Method Calls Strike Back

If you want to stay within strict 'refs', you're going to have to do something like:
my $method = "do_something"; $object->$method if $object->can($method);
Otherwise, you could do something like:
$object->"do_$something";
I would HIGHLY not reccommend turning off any part of strict unless you are a "Perl Jedi Master"(tm) and have many Dark Side points to your name.

------
/me wants to be the brightest bulb in the chandelier!

Vote paco for President!

Replies are listed 'Best First'.
Re: Re: The Dynamic Method Calls Strike Back
by bikeNomad (Priest) on Aug 28, 2001 at 03:03 UTC
    The Dark Side beckons... in Class::Prototyped we used "no strict 'refs'" a mere 19 times...

    If you know why you need it, you should be able to use it. This is the Perl Way. We have the knobs on the back of the set at our disposal.

Re: Re: The Dynamic Method Calls Strike Back
by runrig (Abbot) on Aug 28, 2001 at 02:23 UTC
    $object->"do_$something"; That won't work. But this will:
    eval "\$object->do_$something";
    But I think its better to prepend the 'do_' before you do the method call.
Re: Re: The Dynamic Method Calls Strike Back
by frag (Hermit) on Aug 28, 2001 at 02:32 UTC
    No arguments about 'no strict' being a bad idea, but it's the Principle of the Thing that's bugging me.

    -- Frag.

      "no strict 'refs'" is not necessarily a bad idea, as long as you know what you're doing, and confine it to some lexical blocks. Its practically required when you dynamically create subroutines with AUTOLOAD, (where you also use goto which is usually bad too, but standard AUTOLOAD practice). Its just that even 'no strict' won't help you in the example above :-(

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2024-04-25 21:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found