[tpm] how to resubstitute a captured value

Dave Doyle dave.s.doyle at gmail.com
Fri Apr 19 09:02:26 PDT 2013


didn't know about the s///ee trick though. I had done this:

#!/usr/bin/perl

use strict;

my $match = '^-?(.+?):?$';
my $replace = '"-$1:"';


while (my $line = <DATA>) {
$line =~ s/$match/eval $replace/e;
print $line;
}

__DATA__
stuff
-stuff
stuff:
-stuff:


--
dave.s.doyle at gmail.com


On 19 April 2013 11:59, Dave Doyle <dave.s.doyle at gmail.com> wrote:

> 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/ffc1a880/attachment.html>


More information about the toronto-pm mailing list