Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: execute a string as a function

by Corion (Pope)
on Aug 06, 2013 at 15:30 UTC ( #1048135=note: print w/replies, xml ) Need Help??


in reply to execute a string as a function

While what you describe is possible in principle through Perl built-ins, it's usually best to use the technique of a dispatch table:

my %record_seq_handler= ( 'A' => \&unpack_a, 'B' => \&unpack_B, 'C' => \&unpack_C, ); my $handler= $record_seq_handler{ $RECORD_SEQ_ID } or die "Unknown record sequence '$RECORD_SEQ_ID'"; $handler->( $lines[$_] );

The way you described directly would be through eval, but this approach has various pitfalls that the above code avoids.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1048135]
help
Chatterbox?
[thepkd]: Hi, in trying to create an Array of Hash of Array of Hash. You read it right. Is it possible to dereference it without using temps?
[GotToBTru]: what are temps?

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (11)
As of 2016-12-06 13:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (104 votes). Check out past polls.