jakarta-oro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dan Lipofsky <dlipof...@kurion.com>
Subject RE: $0 in Perl5Substitution
Date Wed, 15 Nov 2000 16:05:46 GMT

> >I notice that Perl5Substitution interprets $0
> >literally instead of as the whole match.  It is
> >documented to do this, so I can't exactly call it
> >a bug, but it is very annoying.  Why was it
> >made this way?  Can we change it?
> 
> Perl doesn't work this way:
> ~> echo foobar | perl -e 'while(<>) { s/f(o)o/{$0}/g; print; }'
> {-e}bar
> ~> echo foobar | perl -e 'while(<>) { s/f(o)o/{$1}/g; print; }'
> {o}bar

> Maybe we should support $& instead?  Things like $&, $', and $` start
> testing the boundary of what the regular expression package should
> handle, since they are not part of the regular expression 
> syntax per se and are Perl internally tracked constructs.
> Backreference interpolations were clearly essential,
> but how far do we take it?

I had ignorantly assumed Perl5 used $0 as the whole match.
Learn something new each day.

It is very useful to be able to reference the whole match.
I would love to see $& supported.  $' and $` are less important IMO.
We could even call it $0 instead of $&, departing from Perl for
something more intuitive.  Yes, I could implement my own substitution
class which did it, but I think it has good general use.
- Dan

Mime
View raw message