Hi Dermot.

Dermot Paikkos wrote:
> Hi Gurus,
>
> I want to read a file and find/build an array of lines that match.

That match what? Each other?

> Is it possible to do something like;
>
> if ( $pattern =~ /$line/ ) {
> dostuff;
> }

Yes, you can do exactly that. The test will succeed if $pattern contains the
string $line, except where $line contains regular expression 'metacharacters'.
To avoid this problem you can do this

    if ( $pattern =~ /\Q$line/ ) {

which protects (escapes) all metacharacters and makes them behave as normal
characters.

However, whether this is what you need to do or not I can't tell without
knowing more about your problem.

> Does perl interpolate the to variables? Or do I need to escape one of
> the variables?

Yes, Perl will interpolate the variables for you, as if they were in double quotes.
Escaping anything only serves to _stop_ it from being interpreted, and force
it to be used literally.

HTH,

Rob





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to