[tpm] how to resubstitute a captured value

Dave Doyle dave.s.doyle at gmail.com
Fri Apr 19 08:59:34 PDT 2013


Hah. Was just about to do the same.

--
dave.s.doyle at gmail.com


On 19 April 2013 11:58, Mike Stok <mike at stok.ca> wrote:

> If I was feeling crazy
>
> #!/usr/bin/perl
> use strict;
> my $match = '^-?(.+?):?$';
> my $replace = '"-$1:"'; # note the quotes...
>
> while (my $line = <DATA>) {
>     $line =~ s/$match/$replace/ee;
>     print $line;
> }
> __DATA__
> stuff
> -stuff
> stuff:
> -stuff:
>
>
> On 2013-04-19, at 11:16 AM, Fulko Hew <fulko.hew at gmail.com> wrote:
>
> #!/usr/bin/perl
> use strict;
> my $match = '^-?(.+?):?$';
> my $replace = '-$1:';
>
> while (my $line = <DATA>) {
>     $line =~ s/$match/$replace/;
>     print $line;
> }
> __DATA__
> stuff
> -stuff
> stuff:
> -stuff:
>
>
> --
>
> Mike Stok <mike at stok.ca>
> http://www.stok.ca/~mike/
>
> The "`Stok' disclaimers" apply.
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/toronto-pm/attachments/20130419/b3c56595/attachment-0001.html>


More information about the toronto-pm mailing list