E
Edi Weitz
man perlop says:
\L lowercase till \E
\U uppercase till \E
\E end case modification
\Q quote non-word characters till \E
However, it doesn't seem to be that simple:
edi@bird:~ > perl -le '$a="Aa-"; print "\Q$a\L$a\E$a"'
Aa\-aa\-Aa\-
edi@bird:~ > perl -le '$a="Aa-"; print "\L$a\Q$a\E$a"'
aa-aa\-aa-
These two cases seem to imply that it isn't as simple as "till \E" but
that the scopes of these modifiers can be nested - in the first case
the scope of \Q extendes beyond the \E, in the second case the scope
of \L extends beyond the \E.
But not if we replace \Q with \U:
edi@bird:~ > perl -le '$a="Aa-"; print "\L$a\Q$a\E$a"'
aa-aa\-aa-
edi@bird:~ > perl -le '$a="Aa-"; print "\L$a\U$a\E$a"'
aa-AA-Aa-
Now the \E ends the scope of both \L and \U, the string behind \E
remains unmodified. This makes sense, kind of, because one could argue
that if the scoping rules were as above the result would be something
like
lc($a . uc($a) . $a)
which would be 'aa-aa-aa-', probably not what people expect.
And what about this one?
edi@bird:~ > perl -le '$a="Aa-"; print "\Q$a\L$a\E$a"'
Aa\-aa\-Aa\-
edi@bird:~ > perl -le '$a="Aa-"; print "\U\Q$a\L$a\E$a"'
AA\-aa-Aa-
By placing \U in front of the string the scope of \Q suddenly ends
at \L? How's that?
Am I missing any rules which could explain this behaviour or are we
just looking at implementation bugs?
FWIW, I'm using Perl 5.8.0 but 5.6.1 also behaves like that.
Thanks in advance for your help,
Edi.
\L lowercase till \E
\U uppercase till \E
\E end case modification
\Q quote non-word characters till \E
However, it doesn't seem to be that simple:
edi@bird:~ > perl -le '$a="Aa-"; print "\Q$a\L$a\E$a"'
Aa\-aa\-Aa\-
edi@bird:~ > perl -le '$a="Aa-"; print "\L$a\Q$a\E$a"'
aa-aa\-aa-
These two cases seem to imply that it isn't as simple as "till \E" but
that the scopes of these modifiers can be nested - in the first case
the scope of \Q extendes beyond the \E, in the second case the scope
of \L extends beyond the \E.
But not if we replace \Q with \U:
edi@bird:~ > perl -le '$a="Aa-"; print "\L$a\Q$a\E$a"'
aa-aa\-aa-
edi@bird:~ > perl -le '$a="Aa-"; print "\L$a\U$a\E$a"'
aa-AA-Aa-
Now the \E ends the scope of both \L and \U, the string behind \E
remains unmodified. This makes sense, kind of, because one could argue
that if the scoping rules were as above the result would be something
like
lc($a . uc($a) . $a)
which would be 'aa-aa-aa-', probably not what people expect.
And what about this one?
edi@bird:~ > perl -le '$a="Aa-"; print "\Q$a\L$a\E$a"'
Aa\-aa\-Aa\-
edi@bird:~ > perl -le '$a="Aa-"; print "\U\Q$a\L$a\E$a"'
AA\-aa-Aa-
By placing \U in front of the string the scope of \Q suddenly ends
at \L? How's that?
Am I missing any rules which could explain this behaviour or are we
just looking at implementation bugs?
FWIW, I'm using Perl 5.8.0 but 5.6.1 also behaves like that.
Thanks in advance for your help,
Edi.