Re: getting arguments
- From: Gunnar Hjalmarsson <noreply@xxxxxxxxx>
- Date: Sun, 29 Jul 2007 01:44:54 +0200
frytaz@xxxxxxxxx wrote:
This script works, but when I'm trying to use it with some other array
use strict;
use warnings;
missing.
sub myagr {
my ($data, $server, $witem) = @_;
my ($cmd, @rest) = split(/ /, $data);
$opts = '^-(one|two|three|four|five)$';
$rest[0] =~ /$opts/ or $badarg=1;
if ($badarg eq 1) {
print "Bad arguments";
} else {
$state;
%args;
for ( @rest ) {
if ( /$opts/ ) {
$state = $1;
$args{ $state } = [ ];
next;
}
push @{ $args{ $state } }, $_;
}
my ( $one, $two, $three, $four, $five ) = map { join ' ',
@{ $args{ $_ } } } qw/ one two three four five /;
# ^ in that line $_ doesn't contain any data
print "one $one two $two three $three four $four five $five";
#prints one two three four five
}
}
why $_ losing data?
I don't understand what you mean. Assuming that this line is added to your script:
myagr ( "$0 @ARGV" );
this is the result I get:
C:\home>perl test.pl "-one first_arg -two second_arg -three third_arg -four fourth_arg -five fifth_arg"
one first_arg two second_arg three third_arg four fourth_arg five fifth_arg
C:\home>
Another thing is that it is a very odd way of passing arguments to a script, and has little to do with what Jens showed you...
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
.
- References:
- getting arguments
- From: frytaz@xxxxxxxxx
- Re: getting arguments
- From: Jens Thoms Toerring
- Re: getting arguments
- From: frytaz@xxxxxxxxx
- getting arguments
- Prev by Date: Re: getting arguments
- Next by Date: Re: Looking to do work with DNS through Perl
- Previous by thread: Re: getting arguments
- Next by thread: Re: getting arguments
- Index(es):
Relevant Pages
|
|