testing for substrings in perl
Dan Langille
dan at langille.org
Mon Jun 7 21:55:55 GMT 2004
On 7 Jun 2004 at 16:31, Chris Costello wrote:
> On Sun, 2003-10-05 at 10:32, Dan Langille wrote:
>
> > I think it might just be easier to do a straight comparison of the first N
> > characters of the two strings where N = length of the directory name.
> >
> > Any suggestions?
>
> You can do:
>
> if ($string =~ /\/?\Q$expr\E/) {
> # ... matches ...
> }
>
> \Q and \E are special metaquoting classes in perlre designed
> specifically for cases like this.
>
> See 'man perlre' for more gory info.
Who is lagged here Chris? Thanks for the reply though.
FWIW, I suspect this was a FreshPorts-releated issue, and I think I
was trying to solve this problem: is any file touched by this commit
in the ports tree?
foreach $value (@{$Files}) {
my ($action, $filename, $revision, $commit_log_element_id)
= @$value;
print " processing $filename\n";
if ($filename =~ m|^/?ports/|) {
$PortTreeCommit = 1;
last;
}
}
--
Dan Langille : http://www.langille.org/
BSDCan - http://www.bsdcan.org/
More information about the freebsd-hackers
mailing list