Gossamer Forum
Home : Products : DBMan : Customization :

All upper case

Quote Reply
All upper case
Hi!

Whats the reg expr for making all characters uppercase? and on the same note for making the first character upper case and the rest lower case.

Many thanks
Quote Reply
Re: [eric74] All upper case In reply to
my $var = 'BLA';

Lowercase......

$var =~ s/(\w)/lc($1)/eg;

Uppercase:

$var =~ s/(\w)/uc($1)/eg;

First Letter Upper:

$var =~ s/(\w)/lc($1)/eg;
$var =~ s/\b(\w)/\U$1/;

Add a g to that last line to make all letters at the beginning of a word uppercase.
Quote Reply
Re: [RedRum] All upper case In reply to
Thanks!!
Quote Reply
Re: [PaulW] All upper case In reply to
Hi again!

A similar problem... Im using:

$rec{'var'} =~ s/^(.{10}).*$/$1.../;

to only display the first 10 characters of a specific variable/record. I just noticed it doesnt work well if it is used for a variable/record that contains linebreaks... i e specifically for fields made in < textareas > etc...

anyway to come around that?

Thanks!
Quote Reply
Re: [eric74] All upper case In reply to
Try using the "/s" modifier with your regexp:

$rec{'var'} =~ s/^(.{10}).*$/$1.../s;

quote perldoc perlretut:
"s modifier (//s): Treat string as a single long line. '.' matches any character, even "\n". ^ matches only at the beginning of the string and $ matches only at the end or before a newline at the end."
kellner
Quote Reply
Re: [kellner] All upper case In reply to
Thanks a bunch!
Quote Reply
Re: [kellner] All upper case In reply to
here we go again (sorry, havent managed to find a good online ref of this...)

Is there a reg expr that simply takes out the last character of a variable? even if its a space " "?

Thanks!
Quote Reply
Re: [eric74] All upper case In reply to
$var =~ s/.$//;

>>(sorry, havent managed to find a good online ref of this...)<<

You're kidding?

http://google.yahoo.com/bin/query?p=perl+regex&hc=0&hs=1

Last edited by:

PaulW: Dec 9, 2001, 9:17 AM
Quote Reply
Re: [PaulW] All upper case In reply to
Thanks! that does it.. but still doesnt solve my prob :(

I have a variable picked up from a file, and it always adds a space to the variable which prevents me from doing a "if $a eq $b" as $b doesnt get that extra space added...

Thought this would solve it but it doesnt as it takes out the last character, but ALSO that extra space...

any ideas?

thanks!
Quote Reply
Re: [eric74] All upper case In reply to
Well just strip off spaces.

$var =~ s,\s+$,,;

Last edited by:

PaulW: Dec 9, 2001, 9:43 AM
Quote Reply
Re: [PaulW] All upper case In reply to
thanks for the link. yeah there are tons of info out there, but I didnt manage to find what I was looking for (or didnt understand...)
Quote Reply
Re: [PaulW] All upper case In reply to
Thats it! Thanks!!
Quote Reply
Re: [RedRum] All upper case In reply to
yeahhhh... its me again.... :)

I'm looking for a way of taking a variable (from a textfield input) and by reg expr stripping off any linebreaks made by the user... Any suggestion would be most appreciated!



Thanks!
Quote Reply
Re: [eric74] All upper case In reply to
Try $var =~ s,\n+,,g;
Quote Reply
Re: [RedRum] All upper case In reply to
Thanks for your quick reply. Unfortunately didnt work...
Quote Reply
Re: [eric74] All upper case In reply to
It should do. WHat did you try exactly?

Last edited by:

RedRum: Jan 3, 2002, 3:24 AM
Quote Reply
Re: [RedRum] All upper case In reply to
I have a textarea for $var which is sent through a form. In db.cgi I take that var and reformat it before I store it, with use of reg expr. If a user enters text in the textarea with linebrakes.. i e:

"whatever

lasldcoedlasdl asldlasd

saldasdldsa" etc

I want to strip those linebrakes and replace them with a space for instance, so that the result is one long line.



Cheers
Quote Reply
Re: [eric74] All upper case In reply to
Try:

$var =~ s,\n+, ,sg;

Last edited by:

RedRum: Jan 3, 2002, 8:45 AM
Quote Reply
Re: [RedRum] All upper case In reply to
Thanks. I didnt get it to work yet. Using a simple input type=text for now...
Quote Reply
Re: [eric74] All upper case In reply to
Hmm thats strange. As far as I know one of the two methods above should have done something at least Pirate