Quick Command Line Arg parsing

To parse command line arguments passed to a script without using a module, parse @ARGV with the following:


foreach my $arg (@ARGV) {
    $a = 1, next if $arg eq '-a';
    $b = 1, next if $arg eq '-b';
    $c = 1, next if $arg eq '-c';
}

Note: This is good only for boolean (on/off) command line switches.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.