The array ARGV

Discussion in 'Perl Misc' started by g3000, Jan 19, 2005.

  1. g3000

    g3000 Guest

    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.
    g3000, Jan 19, 2005
    #1
    1. Advertising

  2. "g3000" <> wrote in
    news::

    > 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.
    A. Sinan Unur, Jan 19, 2005
    #2
    1. Advertising

  3. g3000

    g3000 Guest

    Jean - Luc

    u answered my question thanks. Thread closed
    g3000, Jan 19, 2005
    #3
  4. "A. Sinan Unur" <> wrote in
    news:Xns95E3AA041650Aasu1cornelledu@132.236.56.8:

    > "g3000" <> wrote in
    > news::
    >
    >> 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.
    A. Sinan Unur, Jan 20, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bret

    char **argv vs. char* argv[]

    Bret, Aug 31, 2003, in forum: C Programming
    Replies:
    21
    Views:
    4,581
    Richard Heathfield
    Sep 3, 2003
  2. David
    Replies:
    10
    Views:
    5,949
    Richard Heathfield
    Sep 15, 2003
  3. Hal Styli
    Replies:
    14
    Views:
    1,629
    Old Wolf
    Jan 20, 2004
  4. =?ISO-8859-1?Q?Thomas_N=FCcker?=

    sys.argv[0] - 'module' object has no attribute 'argv'

    =?ISO-8859-1?Q?Thomas_N=FCcker?=, Jun 30, 2003, in forum: Python
    Replies:
    0
    Views:
    900
    =?ISO-8859-1?Q?Thomas_N=FCcker?=
    Jun 30, 2003
  5. jab3

    char **argv & char *argv[]

    jab3, Dec 4, 2004, in forum: C Programming
    Replies:
    5
    Views:
    665
    Chris Torek
    Dec 8, 2004
Loading...

Share This Page