"Schiza, Apostolia (ISS Atlanta)" wrote:
> 
> Hello all,
> I have the following small perl script:
> 
> #!\usr\bin\perl
> my $thing;
> 
> open(DATA, "C:\\data.txt") || die "couldn't open data!";
> while(<DATA>)
> {
>         $thing = $_;
> }
> close(DATA);
> 
> open(STUFF, "C:\\stuff.txt") || die "couldn't open stuff!";
> while(<STUFF>)
> {
>         $all_stuff = $all_stuff . $_;
> }
> close(STUFF);
> 
> if( $all_stuff =~ m/$thing/ )
> {
>         print "ok, $thing found \n";
> }
> else
> {
>         print "oops, $thing not found \n";
> }
> 
> My problem is that the file data.txt has only one line with one string which
> has the '$' in it, like this one "Hi$Lia" , and when it goes and does the
> pattern matching, it says that the
> "Hi$Lia" string was not found in the $all_stuff variable, which is not true
> since this variable has this string: "what a nice day. Hi$Liahow are you"
> I guess the problem is with the '$', I tried escaping it but that didn't
> work either.
> How can I make this pattern matching above to work?
> I have included my two sample files  in the case that somebody would like to
> try it...

You need to remove the \n from thing and escape the $ using quotemeta 
or \Q.  Try this version:

use strict;

my $thing;
open DATA, "data.txt" or die "couldn't open data: $!";
{ local $/ = undef;
$thing = <DATA>;
}
close DATA;

my $all_stuff;
open STUFF, "stuff.txt" or die "couldn't open stuff: $!";
{ local $/ = undef;
$all_stuff = <STUFF>;
}
close STUFF;

chomp $thing; chomp $all_stuff;
print "\$thing: '$thing'\n";
print "\$all_stuff: '$all_stuff'\n";

if ($all_stuff =~ m/\Q$thing/is) {
        print "ok, $thing found \n";
} else {
        print "oops, $thing not found \n";
}

__END__

PS Don't cross-post.  Use inline attachments or cut-n-paste.
-- 
  ,-/-  __      _  _         $Bill Luebkert   ICQ=14439852
 (_/   /  )    // //       DBE Collectibles   http://www.todbe.com/
  / ) /--<  o // //      Mailto:[EMAIL PROTECTED] http://dbecoll.webjump.com/
-/-' /___/_<_</_</_    http://www.freeyellow.com/members/dbecoll/
_______________________________________________
Perl-Win32-Web mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-web

Reply via email to