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 ";

which executes and produces the output:
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

and gives this output when I execute it with any arguments:
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


In reply to Reply to replies and update by Maze
in thread Confused about 'Name "main::whenfound" used only once:' by Maze

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.