Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Parsing your script's command line

by grinder (Bishop)
on Jun 14, 2001 at 02:04 UTC ( #88222=perltutorial: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
      #! /usr/local/bin/perl -w
      print "Hello, world\n";
    
  2. or download this
      #! /usr/local/bin/perl -w
      use strict;
      my $thing = shift(@ARGV);
      print "Hello, $thing\n";
    
  3. or download this
      #! /usr/local/bin/perl -w
      use strict;
      my $thing = shift;
      print "Hello, $thing\n";
    
  4. or download this
      #! /usr/local/bin/perl -w
      use strict;
      my $thing = shift || 'world';
      print "Hello, $thing\n";
    
  5. or download this
      #! /usr/local/bin/perl -w
      use strict;
      my $thing = shift or die "Nothing specified on the command line.\n";
      print "Hello, $thing\n";
    
  6. or download this
      my $thing = shift || 'default';
    
  7. or download this
      my $thing = shift;
      $thing ||= 'default' unless defined $thing;
    
  8. or download this
      #! /usr/local/bin/perl -w
      use strict;
    ...
         $switch = undef if $switch;
      }
      print $switch ? 'Goodbye' : 'Hello', ", $thing\n";
    
  9. or download this
      #! /usr/local/bin/perl -sw
      use strict;
      use vars qw/$g/;
      my $thing = shift || 'world';
      print $g ? 'Goodbye' : 'Hello', ", $thing\n";
    
  10. or download this
      #! /usr/local/bin/perl -w
      use strict;
    ...
      getopt('g');
      my $thing = shift || 'world';
      print $opt_g ? 'Goodbye' : 'Hello', ", $thing\n";
    
  11. or download this
      #! /usr/local/bin/perl -w
      use strict;
    ...
      getopt('g', \%args);
      my $thing = shift || 'world';
      print $args{g} ? 'Goodbye' : 'Hello', ", $thing\n";
    
  12. or download this
    Getopt::Mixed::init( 'j=s l:s p=i s=s t=s logfile>l d>p date>p period>
    +p project>
    j type>t');
    
  13. or download this
      while( my( $option, $value, $pretty ) = Getopt::Mixed::nextOption() 
    +) {
        OPTION: {
    ...
      }
      Getopt::Mixed::cleanup();
      die "No project specified via -j.\n" unless $Project;
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perltutorial [id://88222]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2014-09-20 14:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (159 votes), past polls