Dr.Ruud <rvtol+> wrote in comp.lang.perl.misc:
> Anno Siegel:
> > Jürgen Exner:
> >> Davy:
>
> >>> // Input.txt context
> >>> s 1 2
> >>> a 4 5
> >>> a 9 8
> >>>
> >>> // Output.txt context I want
> >>> Sub (wire1, wire2);
> >>> Add (wire4, wire5);
> >>> Add (wire9, wire
;
> >>
> >> I would split() the line,
> >> _s_ubstitute the 's' with 'Sub' and the 'a' with 'Add'.
> >
> > That would take one s/// for each expansion.
>
> Not necessarily:
Well, the immediate implementation with s/// does.
> #!/usr/local/bin/perl
>
> use strict;
> use warnings;
>
> while (<DATA>) {
>
> s/^(?:
> a(?{'Add'})
No fair -- code insertions.
> |s(?{'Sub'})
> |z(?{'Zzz'})
> )
> [[:blank:]](.)
> [[:blank:]](.)$
> /$^R (wire$1, wire$2);/x;
Ah, I'd entirely forgotten about the $^R variable. That's a good use.
> print;
> }
>
> __DATA__
> s 1 2
> a 4 5
[...]
I think the purpose of code insertions is to prove that everything can be
done with a regex
I don't use them much. Last time I looked there were still scoping issues
with surrounding lexicals (but don't take my word for it), so the designation
as experimental was still appropriate.
Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.