Irene Zweimueller wrote:
Dear list,

Hello,

I´m relatively new to Perl, so please be patient.

Welcome to Perl and the beginners list.

I tied to get rid of whitespace characters by the following programme:

my $i="                   USEFUL                   ";


if ($i =~ /\s/)
{
$i =~ s/\s*//;
}

You don't need to use the same regular expression twice.

$i =~ s/\s+//g;

/\s+/ will match one or more whitespace character and will only preform the substitution if a match is found and the /g option means to match the pattern through the whole string, not just the first occurrence of the pattern.

print "xxxxxxxxxx $i xxxxxxxxxx\n";



John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein

--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/


Reply via email to