[tpm] how to resubstitute a captured value
Shlomi Fish
shlomif at shlomifish.org
Fri Apr 19 23:00:14 PDT 2013
Hi Dave, all,
On Fri, 19 Apr 2013 12:02:26 -0400
Dave Doyle <dave.s.doyle at gmail.com> wrote:
> didn't know about the s///ee trick though. I had done this:
>
It's not a good idea to use more than one /e in production code:
http://perl-begin.org/tutorials/bad-elements/#string-eval
> #!/usr/bin/perl
>
> use strict;
>
All of you did not add "use warnings;" as well. You should have.
Regards,
Shlomi Fish
> 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.
> >>
> >>
> >>
> >>
> >>
> >
--
-----------------------------------------------------------------
Shlomi Fish http://www.shlomifish.org/
Escape from GNU Autohell - http://www.shlomifish.org/open-source/anti/autohell/
Chuck Norris reads all messages posted to LKML (= the Linux Kernel Mailing
List), understands them all, and he kills all gnomes he sees in sight.
— http://www.shlomifish.org/humour/bits/facts/Chuck-Norris/
Please reply to list if it's a mailing list post - http://shlom.in/reply .
More information about the toronto-pm
mailing list