By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,468 Members | 1,016 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,468 IT Pros & Developers. It's quick & easy.

Perl: I do not pass parameters to usage() and @_ is defined yet ???

P: 1
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. use Getopt::Long;
  3.  
  4.  
  5.  
  6.  
  7. $l=@ARGV;
  8.  
  9. print "The number of args is " . @ARGV;print "\n"; 
  10.  
  11. my  $bool= GetOptions('help|?' => \$help, 'url=s' => \$url, 'size=i' => \$size);
  12.  
  13.  
  14. ;
  15. if ( !$bool    or $l < 1 || defined $help ){
  16. &usage();
  17.  
  18. print "=======\n";
  19. print "THE END";
  20.   if (@_ ){
  21.   print "Unknown option: @_\n"}
  22.   print "usage: program [--url URL] [--size SIZE] [--help|-?]\n";
  23.  
  24. }  
  25.  
OUTPUT:
=======
C:\>perld.pl --url www --size 15 -david -fass
The number of args is 6
Unknown option: david
Unknown option: fass


usage: program [--url URL] [--size SIZE] [--help|-?]
=======

please explain why the "additional arguments of perld.pl" are passed through sub usage() to @_????
but I call to sub usage() without parameters????????!!!!!!!!!
Oct 16 '07 #1
Share this Question
Share on Google+
1 Reply


KevinADC
Expert 2.5K+
P: 4,059
@_ is global. It will display whatever it's last values were. Since you did not pass any arguments to usage(), @_ is still the values of the paramaters you passed to the script.
Oct 16 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.