Operating System - HP-UX
1834902 Members
3597 Online
110071 Solutions
New Discussion

Re: put variable in uppercase in Perl

 
SOLVED
Go to solution
Ratzie
Super Advisor

put variable in uppercase in Perl

Sorry this should have been posted here.
I have a script that prompts a user for input.


I need to make this into uppercase.
Bere in mind that I also cut the first 4 letters off the use as a variable for a file name.

I need what ever the use types in both prompts to be in uppercase.

print "Enter BLD: ";
chomp (my $bld = );
my $bld4=substr $bld,0,4; #Pull first 4 char out of BLD for naming of file

print "Enter in room:";
chomp (my $room = );

open my $fc, ">$bld4.cust_has" or die "$bld4.cust_has: $!";


I have tried when I print to do the \U but I get an error...

print $f join "," => $acode.$a[0],\U$bld, $room, $a[1], $a[2], "\n";
2 REPLIES 2
Steven E. Protter
Exalted Contributor
Solution

Re: put variable in uppercase in Perl

use local;

$beast = "something";

$capit = ucfirst($beast) # capitalizes first character

$capall = uc($beast);

From O'Reilly Perl Cookbook page 19-21

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
H.Merijn Brand (procura
Honored Contributor

Re: put variable in uppercase in Perl

\U is for regular expressions, and uppercased till the end of string or till \E

SEP, it's not 'use local;', but 'use locale;'

print $f join "," => $acode.$a[0],uc$bld, $room, $a[1], $a[2], "\n";

will only uppercase $bld (uc takes one argument only)

print $f uc join "," => $acode.$a[0], $bld, $room, $a[1], $a[2], "\n";

will uppercase the entire line

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn