SPUG: multi-line substition, all at once.

Charles DeRykus derykus at gmail.com
Wed Jun 24 19:48:22 PDT 2009


On Wed, Jun 24, 2009 at 5:35 PM, Ryan Corder <ryanc at greengrey.org> wrote:

> On Wed, Jun 24, 2009 at 05:25:08PM -0700, John W. Krahn wrote:
> > $ perl -le'
> > my $code = <<__CODE__;
> >  :    sub hello {
> >  :        say "Hello World!";
> >  :    }
> > __CODE__
> >
> > ( $code = "[code]$code\[/code]" ) =~ s/ +://g;
> >
> > print $code;
> > '
> > [code]    sub hello {
> >         say "Hello World!";
> >     }
> > [/code]
>
> >>After I sent my initial email, I had a feeling that your >>answer would
> be the first one back and that is

>> entirely my fault.  I should have specified that

   >>  $code would most likely contain lines

> >> of text before and after the lines that begin with ':'.  >>So, I can't
> just wrap $code with [code] tags and then >> do a simple substitute on it.
>


Er, wouldn't this work even with the added qualification:

$code = "[code]${code}[\\code]";
$code =~ s/^ ://gm;

-- 
Charles DeRykus
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/spug-list/attachments/20090624/4b7bec9e/attachment.html>


More information about the spug-list mailing list