[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] How to do case-independent substitution?



Hi everyone. Probably obvious, but I couldn't figure it out my the Camel
book and manpages, so here goes:

I must process via a perl script files comming down a serial link, and for
each line in the file, substitute certain strings with others. I hit upon
what I thought was a clever way of doing this (saw it somewhere on the
list):

	s/\*(\w+)\*/$formats{$1}/ig;

which finds any strings (identifiers, actually) enclosed by * and does a
table lookup on the "$formats" hash. I made sure to put the "i" on the s
command to match in a case insensitive manner.

But I realize that the hash itself wouldn't match in a case insensitive
way; if i have the string "*tilde*" and "*TILDE*", i would like that both
of them return the "~" character.

I was looking for an "upcase" or "upper" function in perl, but to no avail.

Is there a way to make sure that the matching in the hash is done in a case
insensitive way? How could I make the $1 variable all-uppercase, so that I
would have only one entry in the hash?

Any help would be greatly appreciated.

Louis Chretien
lchretien@jdeq.com