Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have a file with 40K lines. I want to search the entire file and return only the entires with a string "xxx" in it. Furthermore, I want to e-mail the "xxx" events that contain "yyy" or "zzz" or "aaa". I have the code that identified the lines with "xxx", and have the code working with the "yyy", but I want to change it from a variable containing "yyy" to a hash that can be updated to contain everything... i.e. @emailcrit=("yyy","zzz","aaa"); I've tried this, but when I chnage it from $emailcrit (the old variable containing "yyy") to @emailcrit, it breaks. Any ideas?

Replies are listed 'Best First'.
•Re: Pattern matching with hash
by merlyn (Sage) on Mar 19, 2002 at 14:54 UTC
    Well, you're saying "hash" but using an array. Presuming you mean array there, you can convert the contents of the array into a regex that matches any of them simply:
    my $pat = join "|", map quotemeta, @emailcrit; $pat = qr/$pat/; # compile it once
    Do this before any loop. In the loop, you can now use $pat where you would have used your original pattern, and you'll find the entries you desire.

    -- Randal L. Schwartz, Perl hacker

Re: Pattern matching with hash
by Biker (Priest) on Mar 19, 2002 at 14:55 UTC

    I think you will recieve much more help if you show what you've coded so far.


    Everything will go worng!