baxy77bax has asked for the wisdom of the Perl Monks concerning the following question:

hi,

well it has been a while since i posted anything, but .... :)

today i'm dissatisfied with search and replace engines that many editors provide , like notpade++, UE ... well the problem is that they work perfectly when replacing is done on small dataset, but when something like this is done on a dataset that is 1GB in size.... well i'll just say THANK YOU LARRY!.

but where is the problem then, the problem is that my colleges don't do programming and i'm tired of writing these short scripts to modify their documents, so my idea was to make a short template script that they could just modify a bit and run. But after only one week this script looked like a child was hitting the keyboard with a hammer and those random commands were so pose to be lines of Perl code or something . so that was obvious 'no go'

now i decided to do a small script that the user could use from a command line like

./regex.pl Input.file '##(.*?)_kxx' 'KO$1'
to search for expression ##(.*?)_kxx and replace it with a KO$1 , therefore leaving the expression matched under (.*?).

but the problem is, i can't figure out how to pass $1 to the script for evaluation. i tried many ways but none seems to do the job. so please any hint would be more then appreciated :).

#!/usr/bin/perl use strict; while(<DATA>){ $_ =~ s/$ARGV[0]/$ARGV[1]/g; print $_; } __DATA__ |Chlre4|328957|pg._10_#_1 |Chlre4|28893|est.pg.C_80374 |Chlre5|338325|pm.pg._10_#_4
and let say i wish to do this:
regex.pl '\|(\d+)\|' "#$1#"
thnx

Replies are listed 'Best First'.
Re: regex parser needed
by moritz (Cardinal) on Apr 30, 2010 at 09:09 UTC
    You need eval (careful with escaping the delimiter), the /e flag on substitutions (see perlop) or something like String::Interpolate.
    Perl 6 - links to (nearly) everything that is Perl 6.
      Has anybody of you ever used String::Interpolate? Because, judging by the docs alone, it looks like a horrible, overly complex module.
Re: regex parser needed
by AnomalousMonk (Archbishop) on Apr 30, 2010 at 15:42 UTC

    If you do not choose some kind of text templating system, then see ikegami's many patient replies to eval problem and the many other replies and links therefrom.