HELP: How to program command line args 
Author Message
 HELP: How to program command line args

Hi,

I am fairly new to PERL and quite a competent Shell Scripter and in
shell scripts you have $1 to $n for positional parameters on the command
line, how is this done in PERL? I have had a look at the FAQ but to no
avail and my PERL book (PERL from the Ground Up by Michael McMillan,
Osbourne) doesn't seem to mention it.

Any help will be much appreciated.

Regards

Masud

Sent via Deja.com http://www.*-*-*.com/
Share what you know. Learn what you don't.



Sun, 20 Jan 2002 03:00:00 GMT  
 HELP: How to program command line args

first, $ARGV[1] the second parameter... $ARGV[n].

If you want to use something like "myscript -l <bla> -p <blabla>" then
you can use Getopts::Std, which looks like this:

-------------------------
#!/usr/bin/perl

use Getopt::Std;
use vars qw($opt_l $opt_p $oopt_q); #-- there is no , between
the                                            #-- identifiers

getopts("l:p:q"); #-- the : means that there should be passed a value

#--print out the parameters specified
print $opt_l, "\n";
print $opt_p, "\n";
..

--------------------------------------

--Alex


Quote:

> Hi,

> I am fairly new to PERL and quite a competent Shell Scripter and in
> shell scripts you have $1 to $n for positional parameters on the
command
> line, how is this done in PERL? I have had a look at the FAQ but to no
> avail and my PERL book (PERL from the Ground Up by Michael McMillan,
> Osbourne) doesn't seem to mention it.

> Any help will be much appreciated.

> Regards

> Masud

> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


Sun, 20 Jan 2002 03:00:00 GMT  
 HELP: How to program command line args

Quote:

>I am fairly new to PERL and quite a competent Shell Scripter and in
>shell scripts you have $1 to $n for positional parameters on the command
>line, how is this done in PERL? I have had a look at the FAQ but to no
>avail and my PERL book (PERL from the Ground Up by Michael McMillan,
>Osbourne) doesn't seem to mention it.

>Any help will be much appreciated.

>Regards

>Masud



If it's not there, find another book :-)



Note that $#ARGV is the generally number of arguments minus one, because
$ARGV[0] is the first argument, NOT the command name. See ``$0'' for the
command name.

Michel.



Sun, 20 Jan 2002 03:00:00 GMT  
 HELP: How to program command line args

MCMXCIII in <URL::">
[]
[] I am fairly new to PERL

As we can see, because you don't seem to be able to spell the name
of the language correctly. And we're supposed to believe you that you
looked at the FAQ?

[]                         and quite a competent Shell Scripter and in
[] shell scripts you have $1 to $n for positional parameters on the command
[] line, how is this done in PERL? I have had a look at the FAQ but to no
[] avail and my PERL book (PERL from the Ground Up by Michael McMillan,
[] Osbourne) doesn't seem to mention it.

But the perl man page about special variables might have something
to say about it.

Abigail
--
sub f{sprintf'%c%s',$_[0],$_[1]}print f(74,f(117,f(115,f(116,f(32,f(97,
f(110,f(111,f(116,f(104,f(0x65,f(114,f(32,f(80,f(101,f(114,f(0x6c,f(32,
f(0x48,f(97,f(99,f(107,f(101,f(114,f(10,q ff)))))))))))))))))))))))))

  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----



Sun, 20 Jan 2002 03:00:00 GMT  
 HELP: How to program command line args

Quote:

> I am fairly new to PERL and quite a competent Shell Scripter and in
> shell scripts you have $1 to $n for positional parameters on the command
> line, how is this done in PERL? I have had a look at the FAQ but to no
> avail and my PERL book (PERL from the Ground Up by Michael McMillan,
> Osbourne) doesn't seem to mention it.

Then throw your book away. The most complete and up-to-date docs (as
far as your version of Perl is concerned) you can find are surely the
ones sitting in your hard-disk somewhere:

% podgrep command line argument
/opt/GNUperl5.004_04/lib/pod/perlsec.pod:command line arguments, environment variables, locale information (see

% perldoc perlvar
.....
.....


             intended for the script.  Note that $#ARGV is the
             generally number of arguments minus one, because
             $ARGV[0] is the first argument, NOT the command
             name.  See "$0" for the command name.

In case you're wondering, 'podgrep' is an alias of mine:

   alias podgrep 'grep "\!*" /opt/GNUperl5.004_04/lib/pod/*.pod'

You're a competent "shell scripter" .. you knew that one already :)

I also suggest you buy "Learning Perl" (aka The Llama book) by
R. Schwartz and T. Christiansen, published by O'Reilly.

HTH,
Ala



Sun, 20 Jan 2002 03:00:00 GMT  
 HELP: How to program command line args

<URL::">
{}
{} % podgrep command line argument
{} /opt/GNUperl5.004_04/lib/pod/perlsec.pod:command line arguments, environment variables, locale information (see

GNUperl?

How bizarre.

Abigail
--
package Just_another_Perl_Hacker; sub print {($_=$_[0])=~ s/_/ /g;
                                      print } sub __PACKAGE__ { &
                                      print (     __PACKAGE__)} &
                                                  __PACKAGE__
                                            (                )

  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----



Sun, 20 Jan 2002 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Hiding command-line args?

2. command-line args style flags from a file

3. Debug .pl Syntax of command line args ?

4. Case-insensitive Command Line Args

5. command line args not working correctly

6. perl command line args

7. Passing Args to script via web and command line

8. perl command line args

9. Command line args..?

10. Command line args

11. Question: Perl for Windows command line args?

12. Getting command line args

 

 
Powered by phpBB® Forum Software