Re: getting arguments
- From: jt@xxxxxxxxxxx (Jens Thoms Toerring)
- Date: 29 Jul 2007 11:31:47 GMT
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
.
- Follow-Ups:
- Re: getting arguments
- From: Gunnar Hjalmarsson
- Re: getting arguments
- References:
- getting arguments
- From: frytaz@xxxxxxxxx
- Re: getting arguments
- From: Jens Thoms Toerring
- Re: getting arguments
- From: Gunnar Hjalmarsson
- getting arguments
- Prev by Date: Re: getting arguments
- Next by Date: Re: getting arguments
- Previous by thread: Re: getting arguments
- Next by thread: Re: getting arguments
- Index(es):
Relevant Pages
|
|