use strict; use warnings; use Getopt::Long; my $function; my $data = 'file1'; my $length = 4; my $width = 5; my $verbose; die "$0: Argument required.\n" unless @ARGV; GetOptions ( 'function=s' => \$function, 'length=i' => \$length, 'width=i' => \$width, 'file=s' => \$data, verbose => \$verbose, ) or die "Error in command line arguments\n"; if ($function eq 'plot') { my $fh = read_fh($data); print "$_\n" while <$fh>; } elsif ($function eq 'calc') { my $total = $width * $length; print $total; } else { die "Unsupported function\n"; } sub read_fh # Open and Read a file { my $filename = shift @_; my $filehandle; if ($filename =~ /gz$/) { open $filehandle, "gunzip -dc $filename |" or die $!; } else { open $filehandle, "<$filename" or die $!; } return $filehandle; } #### perl calc.pl --length 20 --width 30 #### perl main.pl --function calc --length 20 --width 30 #### ... my $plotlength = 10; my $calclength = 20; ... GetOptions ( ... 'plotlength=i' => \$plotlength, 'calclength=i' => \$calclength, ... ) or die "Error in command line arguments\n";