in reply to Confused about 'Name "main::whenfound" used only once:'
hm - right, i fix up the indentations
use the appropriate things for finding values
put the declarations in the correct 'scope'
use strict
and er... stop the braindeaded use of qw...
and so with various other edits, this is what i've come up with
#!/usr/bin/perl use strict; use warnings; sub argscan{ my @subarg = ($_[0],$_[1],$_[2]); my $argcount; my $found; my $notfound; my @whenfound; if (@ARGV == 1) { return 0; } elsif ($subarg[0] = undef) { $argcount = @ARGV; return $argcount; } else { while ($argcount <= @ARGV) { if ($ARGV[$argcount] == $subarg[0]){ $found++; $whenfound[$argcount] = 1; } else { $notfound++; $whenfound[$argcount] = 0; } $argcount++; } if ($subarg[1] eq "foundcount") { if (defined($found)) { return $found } } elsif ($subarg[1] eq "notfoundcount") { if (defined($notfound)) { return $notfound } } elsif ($subarg[1] eq "huntfor") { if (defined($found)) { return $whenfound[$subarg[2]] } } else {return 0 } } } my $argnumber = argscan(); my $carnumber = argscan(qw(car foundcount)); my $notcarnumber = argscan(qw(car notfoundcount)); my $bunnynumber = argscan(qw(bunny foundcount)); print "there are $argnumber arguments \n there are $carnumber cars there are $bunnynumber bunnies $notcarnumber args are not cars \n ";
there are 0 arguments
there are 0 cars
there are 0 bunnies
0 args are not cars
when I execute it with any given argument
Use of uninitialized value in numeric le (<=) at testargscan.pl line 18.
Use of uninitialized value in array element at testargscan.pl line 19.
Use of uninitialized value in numeric eq (==) at testargscan.pl line 19.
Use of uninitialized value in numeric eq (==) at testargscan.pl line 19.
Use of uninitialized value in array element at testargscan.pl line 21.
Use of uninitialized value in string eq at testargscan.pl line 29.
Use of uninitialized value in string eq at testargscan.pl line 29.
Use of uninitialized value in string eq at testargscan.pl line 29.
Use of uninitialized value in numeric le (<=) at testargscan.pl line 18.
Use of uninitialized value in array element at testargscan.pl line 19.
Use of uninitialized value in numeric eq (==) at testargscan.pl line 19.
Use of uninitialized value in numeric eq (==) at testargscan.pl line 19.
Use of uninitialized value in array element at testargscan.pl line 21.
Use of uninitialized value in numeric le (<=) at testargscan.pl line 18.
Use of uninitialized value in array element at testargscan.pl line 19.
Use of uninitialized value in numeric eq (==) at testargscan.pl line 19.
Use of uninitialized value in numeric eq (==) at testargscan.pl line 19.
Use of uninitialized value in array element at testargscan.pl line 21.
Use of uninitialized value in numeric le (<=) at testargscan.pl line 18.
Use of uninitialized value in array element at testargscan.pl line 19.
Use of uninitialized value in numeric eq (==) at testargscan.pl line 19.
Use of uninitialized value in numeric eq (==) at testargscan.pl line 19.
Use of uninitialized value in array element at testargscan.pl line 21.
there are 0 arguments
there are 1 cars
there are 1 bunnies
args are not cars
which isn't the bahaviour i'm looking for
what I am looking for is a simple test of a subroutine, which I'm trying to use in a larger program for XML handling, cycles through the argument array looking for the values specified when I call it (in this case - cars and bunnies, just because I could) and returning what I ask for.
so should be pretty easy, except I must be doing something fundamentally wrong
thanks for peoples help, and as for tutorials, i've only had a breif look at llama book and read some source code, so i'm not surprised I'm making careless mistakes
i'll get back to it
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Reply to replies and update
by bigmacbear (Monk) on Aug 10, 2006 at 02:18 UTC | |
|
Re: Reply to replies and update
by starbolin (Hermit) on Aug 10, 2006 at 05:45 UTC | |
by ikegami (Patriarch) on Aug 10, 2006 at 05:48 UTC | |
by starbolin (Hermit) on Aug 10, 2006 at 06:08 UTC |