Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: Using Perl Regex to find & replace large chunks in code

by ikegami (Pope)
on Mar 11, 2013 at 19:01 UTC ( #1022848=note: print w/replies, xml ) Need Help??

in reply to Using Perl Regex to find & replace large chunks in code

As a standalone script
local $/; my $search = <>; my $replace = <>; #local $^I = ''; # No backups. local $^I = '~'; # Make backups. while (<>) { s/\Q$search/$replace/g; print; }


$ - - *.cstol search search search ^D replace replace replace ^D
$ search.txt replace.txt *.cstol

You can tweak $search's content as the linked node did if you so desire (but get rid of \Q if you do).

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1022848]
[prathap keerthipati]: how to update perl in unix
[hippo]: yum update perl
[hippo]: Other package managers are available
LanX wouldn't update system Perl!
[Discipulus]: prathap keerthipati might be it is better to install an alternative Perl instead and do not touch the system one
[LanX]: see perlbrew for alternative Perl installations
[marto]: unless you know exactly what you're doing an often saner option is to simply build another Perl rather than replace the system one

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (16)
As of 2017-03-23 10:36 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (285 votes). Check out past polls.