function - How to create a dynamic subroutine name in perl -
i want create dynamic subroutine name in perl, here trial code , getting error "bad name after feed_load::"
#!/usr/bin/perl use strict; use warnings; begin { push @inc, '/freespace/attlas/data/bin/genericloader /feedloaderlib/' } use feed_load; type ="l"; $temptablefunct = "create".$type."temp_table"; feed_load::&$temptablefunct->($tablename); ### pass dynamic sub name here ###
&{ $pkg_name."::".$sub_name }(@args)
or
( $pkg_name."::".$sub_name )->(@args)
these fail, however, because asked perl forbid doing placing use strict;
in program. can disable use strict;
locally
my $ref = { no strict 'refs'; \&{ $pkg_name."::".$sub_name } }; $ref->(@args)
but turns out \&$sub_name
exempt strictures.
my $ref = \&{ $pkg_name."::".$sub_name }; $ref->(@args)
if instead of sub call, needed method call, can use
my $ref = $o->can($method_name); $o->$ref(@args)
or just
$o->$method_name(@args)
Comments
Post a Comment