Re: RegExp Replace Using a Variable
From: ___cliff rayman___ (cliff_at_rayman.com)
Date: 02/26/04
- Next message: Joe Smith: "Re: Substract numeric from a string."
- Previous message: rxl124_at_hehe.com: "Re: assigning back to an array"
- In reply to: Ones Self: "Re: RegExp Replace Using a Variable"
- Next in thread: jan: "Re: RegExp Replace Using a Variable"
- Reply: jan: "Re: RegExp Replace Using a Variable"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 26 Feb 2004 06:56:38 GMT
Ones Self wrote:
>___cliff rayman___ <cliff@rayman.com> wrote in message news:<78T_b.1850$wP3.682@twister.socal.rr.com>...
>
>
>>Ones Self wrote:
>>
>>
>>>I'm trying to replace using a regexp read from a file:
>>>
>>>$string = '123 456 789';
>>>$re = '([258])';
>>>$rep = '|$1|';
>>>
>>>$string =~ s/$re/$rep/g;
>>>
>>>I would like $string to be: 1|2|3 4|5|6 7|8|9
>>>but it is: 1|$1|3 4|$1|6 7|$1|9
>>>
>>>
>>>
>>>
>>>
>>$string = '123 456 789';
>>$re = '([258])';
>>$rep = '|$1|';
>>
>>$doit="\$string=~s/$re/$rep/g";
>>eval "$doit";
>>
>>print $string;
>>
>>
>
>
>I'm dealing with a _lot_ of records (~1.5M lines), eval is
>really slow (about 8 times slower than a static regexp).
>
>
>
OK - I am not sure how to get around this problem using regex commands.
Maybe a guru would know of one of the top of their head. If it were me,
I would generate a little program from perl, then execute it. It would
use the regex's from the file, and a template to generate a perl
executable program to perform the actual work.
-- _____cliff_rayman_____cliff_@_rayman_._com_____
- Next message: Joe Smith: "Re: Substract numeric from a string."
- Previous message: rxl124_at_hehe.com: "Re: assigning back to an array"
- In reply to: Ones Self: "Re: RegExp Replace Using a Variable"
- Next in thread: jan: "Re: RegExp Replace Using a Variable"
- Reply: jan: "Re: RegExp Replace Using a Variable"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|