On Thu, Sep 20, 2001 at 05:22:14PM +0530, Surarchitha Kumar Kudikyala wrote:
> I have a doubt whether it is possible to evaluate a pattern before using
> it in the pattern matching.
> 
> For eg
> 
> string =~  /$pattern/
> 
> here $pattern is a pattern string contains some perl commands like
> lenght(str) etc. I want these commands to be evaluated, and the result of
> this evaluation has to be used in the actual pattern matching.

If $pattern contains Perl code then it's not a "pattern string", it's a
"Perl code string".  To evaluate such a string you probably want eval:

    my $code = 'length($str)';
    my $pattern = eval $code;

    $string =~ /$pattern/;

Read "perldoc -f eval", carefully.

However, using eval is generally a sign of poor design.  What are you
trying to accomplish with this?  Why do you think doing this sort of thing
is the solution?

 
Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

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

Reply via email to