RE: Matching a Scalar Variable



JupiterHost.Net <mailto:mlists@xxxxxxxxxxxxxxx> wrote:

: Thanks for catching my misstatement :)

Thanks for finally making one. :)


: #!/usr/bin/perl
:
: use strict;
: use warnings;
:
: open my $file1_fh, '<', 'file1' or die "file1 open failed: $!";
:
: open my $file2_fh, '<', 'file2' or die "file2 open failed: $!";
: my @match_list = <$file2_fh>;
: close $file2_fh;
:
: while(<$file1_fh>) {
: my $line = $_;
: chomp $line;
:
: for my $match_against (@match_list) {
: chomp $match_against;
: print "Got the string\n" if $line =~ m{$match_against}xms;
: }
: }
:
: close $file1_fh;

Yes, this is the option the OP chose in a message up thread
from here.

The only thing I would change is the repeated chomping of
the matches. On second thought I'll also complain about that
5-space initial indent. :)

open my $file2_fh, '<', 'file2' or die "file2 open failed: $!";
chomp( my @match_list = <$file2_fh> );
close $file2_fh;

.
.
.

for my $match_against (@match_list) {
print "Got the string\n" if $line =~ m{$match_against}xms;
}

Why the {}xms options on the regex? We aren't messing with $/,
so there shouldn't be any multi-line problems. Is it just a
precaution or is their some other reason?

Christmas*, perhaps? :)


HTH,

Charles K. Clarkson
--
Mobile Homes Specialist
254 968-8328


* Christmas is sometimes referred to as "Xmas" in my country.



.



Relevant Pages

  • Re: perilos Friday 16th - TBMG
    ... > Marjorie Clarke said ... ... I think the BBC should put warnings on all their Christmas ... then - the programmes not covered by that warning will mostly ...
    (uk.media.radio.archers)
  • Re: move 7500 files to various directories
    ... Well it is good that you used strict and warnings but it is a pity that you did ... It does not compile as $album_list, ...
    (comp.lang.perl.misc)