in reply to How to eliminate white spaces,tabs,new lines at thestart and end of a long string ??

use strict; my $str = "\n Sugarkannan is a smart guy \n"; $str =~ s/^\s*(.*?)\s*$/$1/; print ">$str<\n";

Prints:

>Sugarkannan is a smart guy<

Update: s/printf/print/


DWIM is Perl's answer to Gödel
  • Comment on Re: How to eliminate white spaces,tabs,new lines at thestart and end of a long string ??
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: How to eliminate white spaces,tabs,new lines at thestart and end of a long string ??
by friedo (Prior) on Nov 24, 2005 at 07:38 UTC
    Any particular reason you used printf instead of print? Or just force of habit from C? Just curious.

      Naughty slip of the finger! 'twould be much better as print.


      DWIM is Perl's answer to Gödel