rspt8a
Last Updated: March 31, 2016
·
24
· jr-duboc
B86a91c873215ee2357101f54047d8fe

A small script that could help beginners trying to build command-line programs in Perl:

use List::Util qw(first);

foreach $arg (@ARGV) {
 $_ = $arg;
 if (/^-/)
 {
      print "$arg is an invocation option\n";
      #Eliminate invocation options from @ARGV before we run the <> operator
      splice @ARGV, first { @ARGV[$_] eq $arg } 0..$#ARGV, -1;
  }
}

while (<>) {
    chomp;
    print "It was $_ that I saw\n";
}
Say Thanks
Respond