On Aug 19, 3:27 am, [EMAIL PROTECTED] (Dr.Ruud) wrote:
> Orson schreef:
>
> > what I need is construct a reg ex pattern and store
> > in variable. I need to concatenate this from many other variables.
> > Then I must use this variable to do a match. Something like this:
> > while (<>)
> > {
> >     chomp;
> >     my $pt = "\d" . "\s" . "\d";
>
> This sets $pt to "dsd".
>
> >     if ( /$pt/  )
> >     {
> >         print("Match also using variable\n");
> >     }
>
> >     if ( /\d\s\d/ )
> >     {
> >         print("Match not using variable\n");
> >     }
> > }
>
> > The second match work if you give input  like "1987 1988", but I
> > cannot get first match to work. I must be confusing perl with /$pt/
>
> Read the documentation of qr().
>
>   my $digit = q{\d};
>   my $wsp   = q{\s};
>
>   my $pt = qr{ $digit $wsp $digit }x;
>   print $pt;
>
> BTW, the "Match not using variable" regex matches only the part "7 1".
> Is that what you want?
>
> --
> Affijn, Ruud
>
> "Gewoon is een tijger."

But once I get it in variable $pt, what syntax to use for the if (/
$pt/) statemet?

I need to test if the pattern matches each line in file.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to