in reply to Store last value of for loop
The for loop you are showing does not initialize the value as 0 and will print 0, not 1, as the first value:
perl -e ' my @a=(1,1,1,1,1,1,1,1); $i=0; for my $id(@a){ print $i; $i+ ++; } ' outputs 01234567
But $i=0; certainly does initialize. Put that $i somewhere it is executed only once.
I hope your code was only an example. The number of articles in @article_id can be found simply by providing scalar context:
perl -e ' my @a=(1,1,1,1,1,1,1,1); my $i= @a; print "$i\n"; ' outputs 8
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Store last value of for loop
by sandy1028 (Sexton) on Jan 15, 2009 at 09:47 UTC | |
by jethro (Monsignor) on Jan 15, 2009 at 14:06 UTC |