Ajey Kulkarni wrote:
Gunnar Hjalmarsson wrote:
Ajey Kulkarni wrote:
I would like to remove all the spaces & tabs from a variable.
No, you wouldn't. You would like to remove possible whitespace from
the beginning and end of a string.
my($word) = " Detail Design Activity Included ";
$word =~ s/^\s*(\D*)\s*$/$1/;
It's best done using two substitutions:
$word =~ s/^\s+//;
$word =~ s/\s+$//;
Thanks a ton Gunnar,
How about the intermediate blanks? Is there a way to recursively take
all blanks/tabs that occur??
Did you really want that? In that case I misunderstood you; Please
disregard my previous suggestion.
To actually remove *all* whitespace, you can simply do:
$word =~ s/\s+//g;
Read about the /g modifier in the description of the s/// operator in
"perldoc perlop".
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>