[tpm] how to resubstitute a captured value
Mike Stok
mike at stok.ca
Fri Apr 19 08:58:38 PDT 2013
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/2111fcc5/attachment.html>
More information about the toronto-pm
mailing list