Advertisement
Guest User

How can I pass command-line arguments to a Perl program

a guest
Feb 27th, 2012
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. script.pl "string1" "string2"
  2.  
  3. use Getopt::Long;
  4. my $data = "file.dat";
  5. my $length = 24;
  6. my $verbose;
  7. $result = GetOptions ("length=i" => $length, # numeric
  8. "file=s" => $data, # string
  9. "verbose" => $verbose); # flag
  10.  
  11. $numArgs = $#ARGV + 1;
  12. print "thanks, you gave me $numArgs command-line arguments.n";
  13.  
  14. foreach $argnum (0 .. $#ARGV) {
  15.  
  16. print "$ARGV[$argnum]n";
  17.  
  18. }
  19.  
  20. foreach my $arg (@ARGV) {
  21. print $arg, "n";
  22. }
  23.  
  24. while (my $line = <>) {
  25. process_line($line);
  26. }
  27.  
  28. while (my $arg = shift) {
  29. print "Found argument $argn";
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement