http://qs1969.pair.com?node_id=1185096

jnarayan81 has asked for the wisdom of the Perl Monks concerning the following question:

How to wrap multiple programs in one main program?

perl Main.pl plot -file FILE -length LENGTH

perl Main.pl calc -length 20 -width 30

So Main.pl contains two sub-programs 'plot' and 'calc'. User can call anyone of them, based on their need.

################# PLOT program here #!/usr/bin/perl -w use Getopt::Long; my $data = "file1"; my $length = 4; my $verbose; GetOptions ( "length=i" => \$length, "file=s" => \$data, "verbose" => \$verbose ); if (!@ARGV) { print "$0: Argument required.\n"; exit 1 } my $fh = read_fh ($data); while (<$fh>) { print "$_\n"; } ##sub here # Open and Read a file sub read_fh { my $filename = shift @_; my $filehandle; if ($filename =~ /gz$/) { open $filehandle, "gunzip -dc $filename |" or die $!; } else { open $filehandle, "<$filename" or die $!; } return $filehandle; } ################# CALC program here #!/usr/bin/perl -w use Getopt::Long; my $width = 5; my $length = 4; my $verbose; GetOptions ( "width=i" => \$width, "length=i" => \$length, "verbose" => \$verbose ); if (!@ARGV) { print "$0: Argument required.\n"; exit 1 } my $total=$width*$length; print $total;