in reply to execute a string as a function
dispatchers are good, but with DRY principle you may use code like this
use warnings; use strict; sub unpack_a { print "a(@_)\n"; 11 } sub unpack_b { print "b(@_)\n"; 22 } my $RECORD_SEQ_ID = 'a'; local $_ = 0; my @lines = 42; my $res = do { no strict 'refs'; &{"unpack_$RECORD_SEQ_ID"} ($lines[$_ +]) }; print $res;
Yes, it's not so secure if you don't understand what you're doing, and it's around 20% slower then dispatchers which is usually does not matter.