G
GarfGarf
Hi all,
I'm trying to remove from a string another string that is contained in
a variable. The contents of the variable could be anything. However, if
the varibale contains certain characters the substibution fails..
e.g.
#!/usr/bin/perl -w
my $main="the cat sat on the mat (who is black)";
my $one="the";
my $two="cat";
my $three="(who is black)";
my $four="(who is black"; #notice deliberate missing last bracket
try($main,$one);
try($main,$two);
try($main,$three);
try($main,$four);
sub try {
my ($in,$pat)=@_;
$in=~s/$pat//;
print "$in\n";
}
when run it gives:
cat sat on the mat (who is black)
the sat on the mat (who is black)
the cat sat on the mat ()
Unmatched ( in regex; marked by <-- HERE in m/( <-- HERE who is black/
at /tmp/try.pl line 18.
how can I prevent this.. and allow item four to work?
Thanks.
I'm trying to remove from a string another string that is contained in
a variable. The contents of the variable could be anything. However, if
the varibale contains certain characters the substibution fails..
e.g.
#!/usr/bin/perl -w
my $main="the cat sat on the mat (who is black)";
my $one="the";
my $two="cat";
my $three="(who is black)";
my $four="(who is black"; #notice deliberate missing last bracket
try($main,$one);
try($main,$two);
try($main,$three);
try($main,$four);
sub try {
my ($in,$pat)=@_;
$in=~s/$pat//;
print "$in\n";
}
when run it gives:
cat sat on the mat (who is black)
the sat on the mat (who is black)
the cat sat on the mat ()
Unmatched ( in regex; marked by <-- HERE in m/( <-- HERE who is black/
at /tmp/try.pl line 18.
how can I prevent this.. and allow item four to work?
Thanks.