Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

uppercase anyone? 3

Status
Not open for further replies.

LinuXelite

Programmer
Jun 21, 2002
150
CA
$ti = "bon mixte CasE";
#s/.*/\U&/;
#s/^(\w)/U($1)/e;
#$ti =~ s//\U$1\E/g;
$ti =~ s/(\b)(\w)/\U\2/g;
print "\n:\t$ti\n";


none of these worked...
It changed the first letter of each word.
I dont quite get the regular expression yet.


 
Hi LinuXelite,

% cat testdata
ab cd ef gh
--------------
% cat u.pl
#!/usr/bin/perl

open (FILE, "testdata");
while (<FILE>){
$_ =~ s/(.*)/\U$1\E/;
print $_;
}
--------------
% u.pl
AB CD EF GH
--------------


Hope that helps,
Grant.
 
This help a lot...

=~ s/(.*)/\U$1\E/;

replace * (.*) with \U (uppercase) $1 = string \E (all?) /;

Thank you!!


 
Other ways ...
Code:
$ti =~ tr/a-z/A-Z/;
$ti = uc $ti;

jaa
 
According to the Perl Cookbook (ala Ram), it's preferable to use uc() or \U because they support extended characters, locales, etc.

Code:
#! /usr/bin/perl -w
use strict;

my $filename = shift || &quot;input.txt&quot;;
open FILE, &quot;< $filename&quot;
   or die &quot;Can't open $filename&quot;;
while ( <FILE> ) 
{ 
  print uc; 
}
close FILE
   or die &quot;Can't close $filename&quot;;

For more information, please see the perlfaq4, perllocale and (of course) perlfunc man pages.

Hope this helps...

-- Lance
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top