in reply to Re^7: Calling a sub from a variable ?
in thread Calling a sub from a variable ?
I think the point was the reverse - if I load a line from a file, perl buffers a whole chunk. Then I "eval STR" multiple times before hitting the disk for the next chunk. Or the point was that we eval the same STR multiple times through the life of the program, but only read from disk once (for the given string). Either way, the single disk IO is something we can't avoid, but the multiple eval is.
Personally, if I were designing this from the ground up, I would mandate that all functions were actually package methods (that take the package name as the first argument). Then I could do something like this:
my ($package, $func) = extract_from_line($_); $package->$func($_);
Doesn't get any faster than that. We're still using hashes here, but we allow perl to figure that out. The symbol table is just way too useful - and here we're getting it while still using strict.
Alternatively, without forcing package method semantics, you could bypass strict refs and access the symbol table directly. But, as that is a bit more complex and unreadable, I'll leave that for a future node if you need to go that way.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^9: Calling a sub from a variable ?
by dragonchild (Archbishop) on Mar 22, 2005 at 15:25 UTC |