in reply to Improving a script to search for keywords in a file
brian_d_foy gave you pretty much the answer you need, but he didn't mention some of the foibles in your code that make it clear Perl is not your first language. :)
Perl is pretty good at handling lists of things, to the extent that there is a special version of the for loop to itterate over lists. Your nested loops could be rewritten as:
for my $line (@lines){ for my $line2 (@lines2){ next if $line !~ /$line2/; print $line; print "\nyes $line2 exists\n\n"; } }
One side effect of that is to remove $a and $b - which actually are special variables in Perl because they are used as the two arguments passed into a sort block.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Improving a script to search for keywords in a file
by Anonymous Monk on Feb 19, 2006 at 23:18 UTC | |
by GrandFather (Saint) on Feb 20, 2006 at 01:09 UTC | |
by graff (Chancellor) on Feb 20, 2006 at 01:42 UTC |