in reply to Recognizing all-caps line
Try either of the following:
$line =~ m/^[[:upper:]]+$/ # or
$line =~ m/^\p{IsUpper}+$/
the [: ... :] is no character class, although it looks like one.
To make it (part of) a character class, you need another set of brackets around it.
don't go for m/^[A-Z]+$/ for world peace international reasons ;-)
See perldoc perlre too.
$line !~ m/[[:^upper:]]/ # or
$line !~ m/\P{IsUpper}/
(think: do not match a line that contains anything that's not an uppercase letter)
Edit: corrected a number of mistakes.
Thanks especially to davido(++) for pointing out the ones I didn't find myself. Strange enough, while the necessity of the double brackets is not in doubt, I don't get any warnings when omitting them (perl5.8.3, Linux), the code just never tests true.
Another Edit: I guess that's because it looks like a character class to Perl. So why did it throw errors when davido tried it?
Another edit (and moved this discussion to the bottom of the node) -
I tried m/[:^upper:]/; which bypasses warnings.
Congratulations to us, we found a bug.
Cheers, Sören
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Recognizing all-caps line
by davido (Cardinal) on Oct 27, 2004 at 21:46 UTC |