Check specific number arguments

Problem

You want to check a specific number of arguments, have been supplied to your Perl script.



Solution

This snippet at the example tab, demonstrates how to check that 2 args, were postfixed to the Perl script.

If you only want to check one, then use ARGV!=0, for three 2, etc.



Example


Arguments are supplied via the ARGV array.

if($#ARGV!=1) { die("Usage: $0 ...n"); }



Reference

[tags]Perl argument handling, Perl Coding School[/tags]



Leave a Reply

Your email address will not be published. Required fields are marked *