develooper Front page | perl.beginners | Postings from March 2002

@ARGV question

Thread Next
From:
Laycock, Angus
Date:
March 18, 2002 02:57
Subject:
@ARGV question
Message ID:
3E9909F7B5E3D411B04300508BB33046092C6638@exlon04.lehman.com
Hi There.

I have this piece of code which I call with the following; array.csh "one"
"two" "three four" "five" "sic cod"

#!/opt/perl-5.6.1/bin/perl -w
$count=0;
print " ARGV $#ARGV\n\n";

while (<$ARGV>) {
        print "count $count $ARGV[$count]\n";
        $count++;
}

I get the following output:
 ARGV 4

count 0 one
count 1 two
count 2 three four
count 3 five
count 4 sic cod
Use of uninitialized value in concatenation (.) or string at array.csh line
9.
count 5 
Use of uninitialized value in concatenation (.) or string at array.csh line
9.
count 6 

Why does the the while loop keep going and not stop? It does stop if I take
the -w out.

I can get it to work like this;

$count=0;
$total = $#ARGV;

while ( $count <= $total ) {
        print "count $count $ARGV[$count]\n";
        $count++;
}

Could someone tell me the best way. I assumed the first option would be the
best but it does not work.

Thanks

Angus 




------------------------------------------------------------------------------
This message is intended only for the personal and confidential use of the designated recipient(s) named above.  If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited.  This communication is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product, an official confirmation of any transaction, or as an official statement of Lehman Brothers.  Email transmission cannot be guaranteed to be secure or error-free.  Therefore, we do not represent that this information is complete or accurate and it should not be relied upon as such.  All information is subject to change without notice.



Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About