[lug] sed replacment issue?

Ron Wright halsaves at gmail.com
Wed Jul 13 12:06:28 MDT 2005


On 7/11/05, David L. Anselmi <anselmi at anselmi.us> wrote:
> corn man wrote:
> [...]
> > There is no perticular reason I'm stuck with sed.
> >
> >        %lpage = $PHAN->fetchhash;    # get page info in hash
> >
> > into
> >        $lpage_hashref = $PHAN->fetchrow_hashref;
> >        %lpage = %$lpage_hashref;    # get page info in hash

#!/usr/bin/perl -p
s/(\s*)%(\w+) = \$(\w+)->fetchhash;/${1}\$${2}_hashref =
\$${3}->fetchrow_hashref;\n${1}%${2} = %\$${2}_hashref;/;

The regular expression should be one long line.  It should preserve
indenting and comments.

Run it like this:

alter_code.pl < old_code.pl > new_code.pl

> I've never had much luck (or seen examples) of doing multi-line things
> with sed.  I'd use awk instead.  Or wait a bit and a Perl wizard will
> post you a one liner.

I'm still a Perl Apprentice.

Ron Wright



More information about the LUG mailing list