>How exactly does on pre-compile the regex? I would be interested in seeing
>this.

>[Jess]

Three cases:
a) Hardcode - /(\w{5})(something)(\w{5})/
b) Intepolate variable in the search variable, value remaining constant throughout the 
program
   $var = something
   /(\w{5})(something)(\w{5})/o 

c) If the value is going to change, 
   then use eval to  build up a whole block 

I am quoting an example from Perl Cookbook 6.10 (See 6.10 for more details..It 
discussed on speeding up Interpolated matches)

#######
@pop = qw(A,B,C,D,E,F,G);
  
$code = 'while defined($line = <>)) {';
for $state (@pop) {
    $code  .= "\tif (\$line =~ /\\b$state\\b/) {print \$line;next;}\n";
}
$code  .= '}';

eval $code;
die if @!;
#########


          
   


-----Original Message-----
From: Shishir K. Singh [mailto:[EMAIL PROTECTED]]
Sent: Monday, June 24, 2002 5:07 PM
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: RE: matching extracharacters


>Hi all,
>I would like  to match a string variable in a longer string  retreiveing
>the match plus 5 extra characters at each side of the
>match.
>This what I mean:

>$var = 'something';
>$line = 'SDFGHAsomethingWDFTsft';

>and, I would like  to get in a new variable the string
>'DFGHAsomethingWDFTs'.
>Any help in doing this will be very appreciated.


$line = 'SDFGHAsomethingWDFTsft';
$var = "something";

@x = ($line =~ /(\w{5})($var)(\w{5})/);
##or $newVar = $1.$2.$3;

You may consider using eval to precompile the expression in case you have a 
lot's of records to regex on !! This will speed it up!!

Cheers 
Shishir





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


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

Reply via email to