Ramesh's solution works even better than the built-in lc (lowercase)
function that I would have recommended. Apparently the regex engine is very
powerful <g>
I wrote a short script to test the difference. Here's the result
the transliteration (tr) code took:
0 wallclock secs ( 0.11 usr + 0.00 sys = 0.11 CPU)
the lowercase (lc) code took:
1 wallclock secs ( 0.98 usr + 0.00 sys = 0.98 CPU)
I dumped a one megabyte ascii text file into the script to get these
results. Try it and have fun...
[here's the benchmark code]
# --------------------------------------------------------------------------
--
@All_Quotes=<DATA> ; # everything after the __END__ token
# --------------------------------------------------------------------------
--
use Benchmark;
$t0 = new Benchmark;
# ... transliteration code here ...
foreach $foo(@All_Quotes){
$foo =~ tr/[A-Z]/[a-z]/;
};
$t1 = new Benchmark;
$td1 = timediff($t1, $t0);
$t2 = new Benchmark;
# ... lc function code here ...
foreach $bar(@All_Quotes) {
$bar =~ lc($bar) ;
};
$t3 = new Benchmark;
$td2 = timediff($t3, $t2);
print "the transliteration (tr) code took:\n",timestr($td1),"\n";
print "the lowercase (lc) code took:\n",timestr($td2),"\n";
__END__
Pastes a ton of ASCII text here after the END marker.
It provides the DATA for the script to process.
[end benchmark code]
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Chandra
Ramesh
Sent: Wednesday, February 14, 2001 2:11 AM
To: Shil; [EMAIL PROTECTED]
Cc: Chandra Ramesh
Subject: RE: conversion
Hello,
Use "transpose (tr)" to convert from one case to another..
For Eg: Assuming $tmp has all Capital letters and you want to convert to
small letters:
$tmp =~ tr/[A-Z]/[a-z]/;
Hope it helps,
Regards,
Ramesh Chandra
-----Original Message-----
From: Shil [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, February 14, 2001 3:36 PM
To: [EMAIL PROTECTED]
Subject: conversion
Hi,
I am very surprised by the power of regex in perl.Could you tell me how
to convert Capital Letters of Enlish Alphabet to Small ones ie If we enter
in Capital what we get is in small letters.
That is conversion of capital letter in Small ones
Thanks and regards
bye
shailja
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/activeperl
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/activeperl