Gladstone Daniel - dglads wrote:
What would be the simplest way to remove leading and trailing blanks
from a user input?

To remove just blanks (but preserving possible trailing newline):

  s/^ +//, s/ +$// for $input;

To remove all whitespace:

  s/^\s+//, s/\s+$// for $input;

I like this idiom, because you can easily trim several variables at once:

  s/^\s+//, s/\s+$// for $foo, $bar, $baz;
  s/^\s+//, s/\s+$// for @array;
  s/^\s+//, s/\s+$// for values %hash;

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to