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

@ARGV question

Thread Next
Laycock, Angus
March 18, 2002 02:57
@ARGV question
Message ID:
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
print " ARGV $#ARGV\n\n";

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

I get the following output:

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
count 5 
Use of uninitialized value in concatenation (.) or string at array.csh line
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;

$total = $#ARGV;

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

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



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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About