in reply to Re: perlmonks downloadable code blocks
in thread perlmonks downloadable code blocks

The reason I wanted the while is because I update each code block with the number corresponding to which code block it is. Here is an example
my $post_body ='<c>this is the first code block code</c> This is <c>an +other code block</c>'; my $part = 1; $part++ while $post_body =~ s/<c>(.*?)<\/c>/<a href='download?part=$p +art'>Download Me<\/a><pre>$1<\/pre>/i; print $post_body, "\n";
And I will have this as an output:
<a href='download?part=1'>Download Me</a><pre>this is code</pre> This +is <a href='download?part=2'>Download Me</a><pre>more code</pre>
Am I missing something, because I still don't see how I can have the output that I want if I use the global switch.

Replies are listed 'Best First'.
Re^3: perlmonks downloadable code blocks
by ikegami (Patriarch) on Apr 12, 2008 at 02:42 UTC
    Ah good point. e modifier to the rescue.
    my $part; $post_body =~ s{<c>(.*?)<\/c>}{ ++part; qq{<a href='download?part=$part'>Download Me</a><pre>$1</pre>} }gei;