[ale] OT: Perl Question
Mike Fletcher
fletch at phydeaux.org
Fri Nov 12 15:29:56 EST 1999
>>>>> "Robert" == Robert L Harris <nomad at rnd-consulting.com> writes:
Robert> Ok, I'm writing a perl script that looks at files in
Robert> specific directories. At one point, I'm trying to grep
Robert> file names out of an array. I'm using:
Robert> $Skip=grep(/$File/, at FileList);
Robert> Yes, I do want a scalar returned. At any rate, there is a
Robert> point where $File="c++decl" and then I get this error:
Robert> //usr/bin/c++decl/: nested *?+ in regexp at
Robert> ./wanderblock.pl line 170.
Robert> Anyone know a way around this? Basically, all I need to
Robert> know is if $File is in @FileList, not it's position or
Robert> anything else.
You want to use either the \Q\E special escapes, or the
corresponding `quotemeta' function:
=item quotemeta EXPR
=item quotemeta
Returns the value of EXPR with all non-alphanumeric
characters backslashed. (That is, all characters not matching
C</[A-Za-z_0-9]/> will be preceded by a backslash in the
returned string, regardless of any locale settings.)
This is the internal function implementing
the C<\Q> escape in double-quoted strings.
If EXPR is omitted, uses C<$_>.
E.g. in your case one of:
{my $f = quotemeta $File; $skip = grep /$f/, @FileList}
or
$skip = grep /\Q$File/, @FileList;
--
Fletch | "If you find my answers frightening, __`'/|
fletch at phydeaux.org | Vincent, you should cease askin' \ o.O'
678 443-6239(w) | scary questions." -- Jules =(___)=
| U
More information about the Ale
mailing list