Well, you half listened to the replies you got to your first node, but you could have done better. You've not supplied any data. You've not shown us what you expect as output. You've not supplied a stand alone script we can run to check your results and that we can correct to verify the errors we might see. You've not even shown us what you do get as output.

However, given you've made a partial effort, I'll provide a partial answer. First off: always use strictures, especially when they tell you things you don't understand! Your C is showing through! Perl does not use 'break' and 'continue', it uses 'last', 'next' and 'redo'. The following rework of your code at least runs, although it may not yet do what you want:

#!/usr/bin/perl use strict; use warnings; my $names = <<NAMES; N 2 N 3 N 4 N 5 OR NAMES my $data = <<DATA; Notification 2 Notification 1 Order DATA open my $in1, '<', \$names or die "Can't open names: $!\n"; open my $in2, '<', \$data or die "Can't open data: $!\n"; my @leapStrings = <$in1>; chomp @leapStrings; close $in1; my @vldbStrings = <$in2>; chomp @vldbStrings; close $in2; for my $leapString (@leapStrings) { print $leapString; $leapString =~ s/^\s+|\s+$//g; my $found; for my $vldbString (@vldbStrings) { $vldbString =~ s/^\s+|\s+$//g; $vldbString =~ s/Notification\s+(\d+)$/N $1/g; $vldbString =~ s/Order/OR/g; if ($leapString =~ m/$vldbString/i) { $found = 1; last; } } if ($found) { print "\t FOUND IN VLDB =====\n"; } else { print "\t NOT FOUND IN VLDB =====\n"; } }

Prints:

N 2 FOUND IN VLDB ===== N 3 NOT FOUND IN VLDB ===== N 4 NOT FOUND IN VLDB ===== N 5 NOT FOUND IN VLDB ===== OR FOUND IN VLDB =====

I had to invent data of course because you gave none. I also changed your opens to the three parameter version which is safer and clearer (although I did a sneaky "use a string as a file trick" which may be cause for confusion). I used lexical file handles which are also safer. These are both techniques you should always use!

There are a bunch of things I'd improve in this script which would make it work better with large files, but as you don't indicate how much data you are dealing with I'll leave that for a later date.

True laziness is hard work

In reply to Re: Pattern Match is not working by GrandFather
in thread Pattern Match is not working by Lancy

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.