Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > The array ARGV

Reply
Thread Tools

The array ARGV

 
 
g3000
Guest
Posts: n/a
 
      01-19-2005
I have read that the array ARGV holds the command line arguments.

is there a way to pass a hash ( list ) as an argument on the command
line?

I know in a sub routine @_ can be a hash.

But I want to do something like

myprogram.pl (key1=>'value1',key2=>'value2')

and inside the sub in my program be able to
sub1
{
my %options = @_;
.....
}
when I have a call at the end being
sub1(@ARGV);

dont think it can be done but I just want to be positive.

 
Reply With Quote
 
 
 
 
A. Sinan Unur
Guest
Posts: n/a
 
      01-19-2005
"g3000" <(E-Mail Removed)> wrote in
news:(E-Mail Removed) oups.com:

> I have read that the array ARGV holds the command line arguments.


It is @ARGV. ARGV is a bareword.

> is there a way to pass a hash ( list ) as an argument on the command
> line?


Huh?

What makes you think the shell knows about hashes etc?

Is this what you are asking?

#! /usr/bin/perl

use strict;
use warnings;

use Data:umper;

mydumper(@ARGV);

sub mydumper { print Dumper { @_ }; }

__END__

C:\Home> c.pl key1 value1 key2 value2 sdlkfj ewruh
$VAR1 = {
'key2' => 'value2',
'key1' => 'value1',
'sdlkfj' => 'ewruh'
};

> I know in a sub routine @_ can be a hash.


That is a non-sensical statement. Please read

perldoc perlsub

> when I have a call at the end being
> sub1(@ARGV);
>
> dont think it can be done but I just want to be positive.


If I understood you right, of course 'it' can be done. @ARGV is an array
just like any other array. You can initialize the keys and values of a
hash from it the same way you would with any other array.

Sinan.
 
Reply With Quote
 
 
 
 
g3000
Guest
Posts: n/a
 
      01-19-2005
Jean - Luc

u answered my question thanks. Thread closed

 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      01-20-2005
"A. Sinan Unur" <(E-Mail Removed)> wrote in
news:Xns95E3AA041650Aasu1cornelledu@132.236.56.8:

> "g3000" <(E-Mail Removed)> wrote in
> news:(E-Mail Removed) oups.com:
>
>> I have read that the array ARGV holds the command line arguments.

>
> It is @ARGV. ARGV is a bareword.


Well, actually, there is a fair bit of magic associated with ARGV:

See perldoc perlvar.

Sinan.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
char **argv & char *argv[] jab3 C Programming 5 12-08-2004 08:15 AM
int main(int argc, char *argv[] ) vs int main(int argc, char **argv ) Hal Styli C Programming 14 01-20-2004 10:00 PM
difference(s) between char** argv and char* argv[] David C Programming 10 09-15-2003 06:58 AM
char **argv vs. char* argv[] Bret C Programming 21 09-03-2003 03:24 AM
sys.argv[0] - 'module' object has no attribute 'argv' =?ISO-8859-1?Q?Thomas_N=FCcker?= Python 0 06-30-2003 02:07 PM



Advertisments