@ARGV is a special array in Perl, it holds the arguments passed to the program as each element of the array. Therefore $ARGV[0] contains the first argument and $ARGV[1] contains the second argument etc. Following is an example of accepting the name and age of the end user as command line arguments and displaying the same as a well formed sentence:
#!/usr/bin/perl #---------------------# # PROGRAM: test_argv.pl # #---------------------# print "My name is $ARGV[0] and I am $ARGV[1] years old\n";
Running the program from command line: -------------------------------------- perl test_argv.pl James 33
Output: ------- My name is James and I am 33 years old
AllBlogToolsFacebook comments for blogger brought to you by AllBlogTools.com , Get Yours?