Perl seems to be an amazingly succint way of writing programs, but I seem to be having a nightmare debugging this simple script!
#!/usr/bin/perl #testargscan.pl - a script for testing use warnings; sub argscan{ if ($#ARGV == 1) {return (0)} else { my @subarg = (qw($_[0] $_[1] $_[2])); my $argcount = 0; my $found; my $notfound; my @whenfound; while ($argcount <= $#ARGV) { if ($subarg[0] = undef) { $argcount = $#ARGV; return $argcount } if ($ARGV[$argcount] == $subarg[0]){ $found++; $whenfound[$argcount] = 1; } else { $notfound++; $whenfound[$argcount] = 0; #goto (proper) } unless ($argcount == $#ARGV) { $argcount++ } } } if ($subarg[1] eq 'foundcount') { unless ($found == undef) { return $found} else {return 0} } elsif ($subarg[1] eq 'argcount'){ unless ($argcount == undef) { return $argcount} else {return 0} } elsif ($subarg[1] eq 'notfoundcount') { unless ($notfound == undef) { return $notfound} else {return 0} } elsif ($subarg[1] eq 'hunt') { unless ($found == undef) { return $whenfound[$subarg[2]]} else {return 0} } else {return 0}; } $argnumber = argscan(undef); $carnumber = argscan(qw (car foundcount)); $notcarnumber = argscan(qw(car notfoundcount)); $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 ";
it's probably a pretty shoddy piece of code, I keep on getting very odd error messages such as:

"Name "main::whenfound" used only once: possible typo at testargscan.pl line 54."

when that isn't true, and sometimes the perl interpreter just freezes
If someone will tell me what i'm missing I can go though the process of feeling stupid for not realising it and then learning from my mistake
PS: It can work, but all the final values will be 0

2006-08-09 Retitled by Corion, as per Monastery guidelines
Original title: 'Confused'


In reply to 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.