Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Parsing your script's command line

by grinder (Bishop)
on Jun 14, 2001 at 02:04 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: perltutorial [id://88222]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-09-18 05:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The PerlMonks site front end has:





    Results (23 votes). Check out past polls.

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.