Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Would you use 'goto' here?

by ask (Pilgrim)
on Dec 06, 2001 at 07:20 UTC ( #129844=note: print w/ replies, xml ) Need Help??


in reply to Would you use 'goto' here?

Once in a while I've used something like

if (exists $commands{$command}) { my ($result) = eval "&$command"; ... }
to avoid the if ($command eq "foo") { &foo } elsif (...) thing. I think I picked it up from Jim Winstead

 - ask

-- 
ask bjoern hansen, http://ask.netcetera.dk/   !try; do();


Comment on Re: Would you use 'goto' here?
Download Code
Re: Re: Would you use 'goto' here?
by blakem (Monsignor) on Dec 06, 2001 at 07:34 UTC
    Is there any reason why string eval is preferable to either one of these:
    { no strict 'refs'; $command->(); # OR &$command(); }

    -Blake

Re: Re: Would you use 'goto' here?
by chromatic (Archbishop) on Dec 06, 2001 at 07:36 UTC
    eval string, from a mod_perl guy! I'd be shocked, if I didn't think you had a good reason. :)

    I'd still prefer subrefs, can, and maybe even some symbolic references with map:

    %commands = map { $_ => \&{ $_ } } keys %commands;

    Season to taste.

    Update: Not that eval is slow, but that eval string has some memory leaks not fixed until 5.8. That can be nasty in mod_perl.

      In a program that'll fork and run another program, do multiple dns lookups, open and read a handful of files, write to the network, wait for the network and much more? Sure, we can eval half the day1 and it won't make much difference if any at all.

       - ask

      1) No, of course not literally half the day. :-)

      -- 
      ask bjoern hansen, http://ask.netcetera.dk/   !try; do();
      

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2014-07-13 06:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (247 votes), past polls