in reply to Looping through a file
Also, note that the elements of the @PARTS array will have the terminating newline at the end, and this will interfere with string comparisons. To get rid of that, you can use:if ($PARTS eq $ordnum) {
Frankly, my preference is use a read loop:chomp(@PARTS = <PARTS>);
And finally, you can make your search a little more efficient by short-circuiting the loop when you've found a match:while (<PARTS>) { chomp; if ($_ eq $ordnum) { ...
for $PARTS (@PARTS) { if ($PARTS eq $ordnum) { # assuming 'eq' is correct here $found = 1; last; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Looping through a file
by baixiaohu (Initiate) on Apr 15, 2008 at 20:23 UTC |