CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Stripping "spaces" ??

 



Always IN Chaos
Novice

Dec 2, 2003, 1:22 PM

Post #1 of 3 (912 views)
Stripping "spaces" ?? Can't Post

how would you do that, I strip comma's with

Code
sub strip_commas { 

local ($strip_commas) = @_;
$strip_commas =~ s/\,//g;
return $strip_commas;


But have no idea how to strip spaces... and once i get that, how to I call upon the sub rutine?


KevinR
Veteran


Dec 2, 2003, 1:58 PM

Post #2 of 3 (911 views)
Re: [Always IN Chaos] Stripping "spaces" ?? [In reply to] Can't Post


In Reply To
how would you do that, I strip comma's with

Code
sub strip_commas { 

local ($strip_commas) = @_;
$strip_commas =~ s/\,//g;
return $strip_commas;


But have no idea how to strip spaces... and once i get that, how to I call upon the sub rutine?


depends if you mean strip all spaces or strip extra spaces. You could do it right in the same sub routine you posted above:


Code
sub strip_commas { 
local ($strip_commas) = @_;
$strip_commas =~ s/\,//g;
$strip_commas =~ s/\s+/ /g;#strips extra spaces and leaves one space
$strip_commas =~ s/\s+//g;#strips all spaces
return $strip_commas;


just take out the one you don't want to use
-------------------------------------------------


davorg
Thaumaturge / Moderator

Dec 3, 2003, 2:07 AM

Post #3 of 3 (906 views)
Re: [Always IN Chaos] Stripping "spaces" ?? [In reply to] Can't Post

KevinR has already answered your question, but I was just wondering why you use "local" to localise the value of $strip_commas. Is it giving something that "my" doesn't? I'd generally use "my" in those situations.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives