in reply to to loop through an array and store each of the subtotals in the elements of another array
After reformatting your posted code, I get something like:
which can be written more cleanly as Your code can be written more cleanly as
#!/usr/bin/perl -w use strict; my @findle = ("fever","febbre","la fièvre","koorts"); my $number = 0; for my $element (@findle) { if (/\Q$element\E/) { print "$_\n"; $number++; #@lines = # print ("there are : " . $number); } }
If you want to cache the elements you hit on, you can combine an array outside the scope of your test with push:
#!/usr/bin/perl -w use strict; my @findle = ("fever","febbre","la fièvre","koorts"); my @hits; for my $element (@findle) { if (/\Q$element\E/) { print "$_\n"; push @hits, $element; #@lines = # print ("there are : " . $number); } }
Note that the length of your @hits array also functions to count the number of hits.
Update: OP added tags, so modified above accordingly.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: to loop through an array
by alexlearn (Initiate) on May 12, 2011 at 20:02 UTC | |
by alexlearn (Initiate) on May 12, 2011 at 21:39 UTC | |
by kennethk (Abbot) on May 12, 2011 at 21:48 UTC | |
by alexlearn (Initiate) on May 13, 2011 at 20:42 UTC | |
by kennethk (Abbot) on May 16, 2011 at 14:11 UTC |