SPUG: multi-line substition, all at once.
Charles DeRykus
derykus at gmail.com
Thu Jun 25 06:33:54 PDT 2009
Here's a horrible possibility using a code assertion:
my $end = 0;
my $st = 0
# no comments to discourage usage
$code =~ s/ ^(?: \s:(?{$st++;}) | (?{ $end++ if $st }) ) /
$st == 1 ? "<code>" : ($end==1 ? "<\\code>" : "")
/gmex;
which produces:
foo bar
baz
<code> sub hello {
say "Hello World!";
}
<\code>asdf
snap
crackle
pop
---
Charles DeRykus
On Thu, Jun 25, 2009 at 12:00 AM, Ryan Corder <ryanc at greengrey.org> wrote:
> On Wed, Jun 24, 2009 at 07:48:22PM -0700, Charles DeRykus wrote:
> | Er, wouldn't this work even with the added qualification:
> |
> | $code = "[code]${code}[\\code]";
> | $code =~ s/^ ://gm;
>
> No, that's the same problem. I can't just wrap the entirety of $code
> inside [code] tags. Using your example and if $code contained the
> following:
>
> my $code=<<__CODE__;
> foo bar
> baz
>
> : sub hello {
> : say "Hello World!";
> : }
> asdf
> snap
> crackle
> pop
> __CODE__
>
> The output would like like this:
>
> [code]foo bar
> baz
>
> sub hello {
> say "Hello World!";
> }
> asdf
> snap crackle
> pop
> [/code]
>
> which doesn't work for me. I need to insert the [code] tags on either
> side of the substitution, inline with any content that may already be
> there.
>
>
> --
> Ryan Corder || () ASCII ribbon campaign
> <ryanc at greengrey.org> || /\ against HTML email
> http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x1CB59D69
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/spug-list/attachments/20090625/2e2899a2/attachment-0001.html>
More information about the spug-list
mailing list