Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > passing multiple values into an argument as an array ?

Reply
Thread Tools

passing multiple values into an argument as an array ?

 
 
Jack
Guest
Posts: n/a
 
      09-23-2006
hi folks,

I am reading in arguments just fine using the code below, but I want to

be able to add a variable number of values into an argument into perl -

I want to be able to say
perl -f value1 value2 ..valueN -v value value2 ..valueN

and store the values of -f in a single array, and -v also (and the
number of passed values could vary !)

If anyone has any tips that would be great - Thanks, Jack

if (@ARGV[0] eq undef) {
$value1=@ARGV[0];
}
if (@ARGV[1] eq undef) {
$value2=@ARGV[1];

 
Reply With Quote
 
 
 
 
usenet@DavidFilmer.com
Guest
Posts: n/a
 
      09-23-2006
Jack wrote:
[a multiposted question]

Don't multipost. It's rude.

--
David Filmer (http://DavidFilmer.com)

 
Reply With Quote
 
 
 
 
Brian McCauley
Guest
Posts: n/a
 
      09-23-2006

wrote:

> [a multiposted question]
>
> Don't multipost. It's rude.


Now I think you are being too terse. At least say

Don't multipost. It's rude. See http://....

> David Filmer (http://DavidFilmer.com)


I went there and found a statement "There is nothing on this website,
and there are no plans to ever have any content here" and a link to
another page on the same website. Can I just say "huh?".

 
Reply With Quote
 
Dave Weaver
Guest
Posts: n/a
 
      09-26-2006
On 22 Sep 2006 20:43:51 -0700, Jack <> wrote:
> I am reading in arguments just fine using the code below, but I want to
> be able to add a variable number of values into an argument into perl -
>
> I want to be able to say
> perl -f value1 value2 ..valueN -v value value2 ..valueN
>
> and store the values of -f in a single array, and -v also (and the
> number of passed values could vary !)


I've just discovered the clever Getopt:eclare module, which can do
just that:

#/usr/bin/perl
use strict;
use warnings;
use Getopt:eclare;

my $args = Getopt:eclare->new(<<END);
-f <value>... a list of values
-v <value>... another list of values
END

my @f = @{ $args->{'-f'} };
my @v = @{ $args->{'-v'} };
print "f = @f, v = @v\n";





 
Reply With Quote
 
DJ Stunks
Guest
Posts: n/a
 
      09-26-2006
Dave Weaver wrote:
> On 22 Sep 2006 20:43:51 -0700, Jack <> wrote:
> > I am reading in arguments just fine using the code below, but I want to
> > be able to add a variable number of values into an argument into perl -
> >
> > I want to be able to say
> > perl -f value1 value2 ..valueN -v value value2 ..valueN
> >
> > and store the values of -f in a single array, and -v also (and the
> > number of passed values could vary !)

>
> I've just discovered the clever Getopt:eclare module, which can do
> just that:
>
> #/usr/bin/perl
> use strict;
> use warnings;
> use Getopt:eclare;
>
> my $args = Getopt:eclare->new(<<END);
> -f <value>... a list of values
> -v <value>... another list of values
> END
>
> my @f = @{ $args->{'-f'} };
> my @v = @{ $args->{'-v'} };
> print "f = @f, v = @v\n";


It's unfortunate that this topic was multiposted, because David Filmer
has already pointed out in perl.beginners that the newest version of
Getopt::Long (version 2.35) supports this functionality natively (ie:
without split()-ing) though the module's author lists this
functionality as 'experimental'.

-jp

 
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
passing a tuple into a class function as a single argument greywine@gmail.com Python 2 11-26-2010 08:24 PM
How to use a passing argument(returned argument)? ±è ÁØ¿µ Ruby 7 11-27-2008 03:53 AM
About the retrogression problem when passing a array variable into a function which takes a pointer as its argument. =?utf-8?B?5YiY5piK?= C++ 4 07-26-2007 09:45 AM
Passing a function as an argument and using the evaluated functionas an argument User1014 Javascript 1 11-30-2006 12:13 PM
Argument-per-argument Passing Trans Ruby 3 01-26-2005 05:58 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57