Re: getting arguments



Gunnar Hjalmarsson <noreply@xxxxxxxxx> wrote:
Jens Thoms Toerring wrote:

my $state;
my %args;
for ( @ARGV ) {
if ( /$opts/ ) {
$state = $1;
$args{ $state } = [ ];
next;
}
push @{ $args{ $state } }, $_;
}

my ( $one, $two, $three ) = map { join ' ', @{ $args{ $_ } } }
qw/ one two three /;

Why the deep data structure? Why not just:

my ($state, %args);
for ( @ARGV ) {
if ( /$opts/ ) {
$state = $1;
next;
}
$args{ $state } = $_;

But then you would only store the last of the words, i.e. for the
command line argument "-one one test 1", would would only keep
the "1" and would not get "one test 1" as I understand the OP
wanted. Or am I missing something?

Regards, Jens
--
\ Jens Thoms Toerring ___ jt@xxxxxxxxxxx
\__________________________ http://toerring.de
.



Relevant Pages

  • Re: Saving expressions as lists?
    ... > to implement APPLY without using macros. ... > to store the arguments to APPLY in a list and evaluate that list. ... APPLY is one of the primitives of scheme -- if you implement it using ... (apply f args)) ...
    (comp.lang.scheme)
  • Re: using function reference
    ... anno4000@xxxxxxxxxxxxxxxxxxxxxx schrieb: ... as then i will need to store the args to be passed to the functions ...
    (comp.lang.perl.misc)
  • Re: using function reference
    ... vabby wrote in comp.lang.perl.misc: ... as then i will need to store the args to be passed to the functions ...
    (comp.lang.perl.misc)
  • Re: using function reference
    ... I really would not want to do stjing like this ... as then i will need to store the args to be passed to the functions ...
    (comp.lang.perl.misc)