The array ARGV

G

g3000

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.
 
A

A. Sinan Unur

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::Dumper;

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top