Your post formatting is a bit off (and there's that trailing "This device belongs to the") but I've seen it updated once since I first opened it, so I suppose you are working on it. If you are having difficulties, you can look at Markup in the Monastery, or ask (maybe in the Chatterbox).

Anyway, the simplest way to check that a string is included in another is to use the index function (it will return the position of the match when there is one, or -1 when the substring can't be found). This would be something like:

my %file2; open my $file2, '<', shift or die; while ( my $line = <$file2> ) { chomp($line); # Do not keep the "\n" at the end of $line ++$file2{$line}; } open my $file1, '<', shift or die; while ( my $line = <$file1> ) { SEARCH: for my $search (keys %file2) { print $line and last SEARCH if index $line, $search > -1; # Ed +it: GotToBTru pointed out I forgot "index" } }
The for loop can be written with grep instead: print $line if grep { index $line, $_ > -1 } keys %file2;. You should use whatever is easier for you to understand and edit

++ to hippo on the variable names (if you have to add a number to a variable name, it's probably not the right name).

Edit2: s/a bit of\K/f/; Thanks to Lotus1.


In reply to Re: searching string from one file in another by Eily
in thread searching string from one file in another by freakpea

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.