jakarta-oro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daniel F. Savarese" <...@savarese.org>
Subject Re: $0 in Perl5Substitution
Date Wed, 15 Nov 2000 05:41:29 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

$& provides the entire match:

~> echo foobar | perl -e 'while(<>) { s/f(o)o/{$&}/g; print; }'
{foo}bar

Granted, Perl doesn't interpret $0 literally in a substitution, but in the
absence of a corresponding Java interpretation, the default should be to
interpret it literally.  Or should it?

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?  It's not a rhetorical
question.  I'm really asking.  Since the information can be extracted from
MatchResult and you can subclass Perl5Substitution or write your own
Substitution implementations, does it make sense to do more interpreting
of a substitution rather than write Java code?

daniel



Mime
View raw message