"Charles K. Clarkson" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > TapasranjanMohapatra <[EMAIL PROTECTED]> wrote: > > : Suppose I have many sub routines in a module abc.pm > : > : package abc; > : > : sub zzzq > : { > : } > : > : sub zzze > : { > : } > : sub zzzr > : { > : } > : > : Now I use this module in another script. I want to call the > : sub routines, as suggested by the argument passed to the > : script. i.e. > : my_script q should call the sub routine zzzq, > : my_script e should call the sub routine zzze, > : ... > > Boy, that looks like a bad idea. It is possible to do this, > but I would rather first explore better solutions. Why do you > want to do this? What are you trying to accomplish? > >
You need to explore perl's OO implementation. If you aren't familiar with OO, don't worry, perl is the best program in the world to learn OO with. Perl wont allow scalar strings to be evaluated as function calls, but you can use strings to call arbitrary class or object methods. This is called reflection or introspection. Note: use warnings; use strict; package abc; sub zzzq { my $proto = shift; print( 'zzzq args: ', join(', ', @_), "\n" ); } sub zzze { my $proto = shift; print( 'zzze args: ', join(', ', @_), "\n" ); } sub zzzr { my $proto = shift; print( 'zzzr args: ', join(', ', @_), "\n" ); } package main; print('Enter Qualifier: (q,r,e): '); chomp( my $arg = <STDIN> ); my $method = 'zzz' . $arg; if ( UNIVERSAL::can( 'abc', $method ) ) { abc->$method( qw| data1 data2 | ); } else { print('error: "', $arg, '" cannot be qualified', "\n"); } Here is the output of several invocations: [EMAIL PROTECTED] temp]$ perl method.pl Enter Qualifier: (q,r,e): q zzzq args: data1, data2 [EMAIL PROTECTED] temp]$ perl method.pl Enter Qualifier: (q,r,e): r zzzr args: data1, data2 [EMAIL PROTECTED] temp]$ perl method.pl Enter Qualifier: (q,r,e): x error: "x" cannot be qualified [EMAIL PROTECTED] temp]$ perl method.pl Enter Qualifier: (q,r,e): e zzze args: data1, data2 please read perldoc perlreftut and perldoc perltoot Enjoy! Todd W. http://waveright.homeip.net/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>