Please read Writeup Formatting Tips. In particular, please wrap code in <code> tags, to prevent mangling. In particular, note how your array indices got linkified.
After reformatting your posted code, I get something like:
#!/usr/bin/perl -w
use strict;
my @findle = ("fever","febbre","la fièvre","koorts");
my $size = @findle;
my $number = 0;
for (my $i=0; $i<$size; $i++) {
if ($_ =~ /$findle[$i]/ ) {
print "$_\n";
$number++;
#@lines = # print ("there are : " . $number);
}
}
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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.