[tpm] how to resubstitute a captured value

Fulko Hew fulko.hew at gmail.com
Fri Apr 19 08:16:37 PDT 2013


Thats what I started with, but...
I forgot to mention that the match expression and replacement
expresssion need to be inside variables
ie.

#!/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:


On Fri, Apr 19, 2013 at 11:07 AM, Dave Doyle <dave.s.doyle at gmail.com> wrote:

> Not the most efficient, but you can just always remove and add them back:
>
> #!/usr/bin/perl
>
> use strict;
>
> while (my $line = <DATA>) {
>  $line =~ s/^-?(.+?):?$/-$1:/;
> print $line;
> }
>
> __DATA__
> stuff
> -stuff
> stuff:
> -stuff:
>
>
> --
> dave.s.doyle at gmail.com
>
>
> On 19 April 2013 10:58, Fulko Hew <fulko.hew at gmail.com> wrote:
>
>>  The subject line may not say it properly, but I need
>> a _single_ (because of other constraints) s/// statement
>> that effectively performs the following:
>>
>> If the string doesn't start with a hyphen and end with colon,
>> then I want them added.
>>
>> ie:
>>
>> stuff   => -stuff:
>> -stuff  => -stuff:
>> stuff:  => -stuff:
>> -stuff: => -stuff:
>>
>> _______________________________________________
>> toronto-pm mailing list
>> toronto-pm at pm.org
>> http://mail.pm.org/mailman/listinfo/toronto-pm
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/toronto-pm/attachments/20130419/d9845bb4/attachment.html>


More information about the toronto-pm mailing list