in reply to Re^2: input switch
in thread input switch

Right, the two main approaches are roughly:

if...elsif... which requires string comparison before deciding which method it'll execute. (and of course, the string comparisons can have their order optimised)

eval()ing, which needs to be wrapped up with a security check to ensure that someone doesn't try to do any "bad things" with it. Which means a series of string compares, to ensure it's a valid choice. Thus effectively becoming roughly the same thing...

I'd argue this latter option is more difficult to maintain, as it could be argued that it'd be easier to miss out of the regexp.

--
RatArsed

Replies are listed 'Best First'.
Re^4: input switch
by Aristotle (Chancellor) on Sep 09, 2002 at 08:54 UTC
    I don't see any eval in the code of my other node.

    Makeshifts last the longest.

      It's still doing a dispatch type of invocation. (so it's late bound) so at the lower levels, it's effectively the same as eval() to an extent -- you're still having to string comparison at runtime to check if the method exists, then invoking the late bound method, which naturally doesn't compile down as well as the early bound option which if...elsif... implies.

      --
      RatArsed

        There's no early binding in Perl. All method calls are symbolic lookups at run time. That means the if elsif method does a dispatch as well as a string comparison. Which is what I already said in my first reply on this thread branch.

        Makeshifts last the longest.