Consider:
#!/usr/bin/perl
if ($ARGV[0]=="-v") {
print "MY name: abc\n";
print "MY student ID:111110\n";
}
if ($ARGV[0]=="-s" && $ARGV[1]==printing_usage_file) {
open (INFILE, $ARGV[1]) or die "An input file is required as argument\n";
$totalbytes=0;
$data="";
while(<INFILE>) {
chomp();
@data=split(/,/);
$totalbytes += $data[1];
}
print "Total number of bytes printed: $totalbytes\n";
}
In this case, what I want is when I run ./perl.pl -v, it prints my name and id.
When I run ./perl.pl -s printing_usage_file, it prints the totalbytes(printing_usage_file file is list like:aaa,240,ccc).
But here when I run /perl.pl -v or ./perl.pl -s printing_usage_file it prints my name,id and the totalbytes. How can I fix it?