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

$string =~ s/^\s+//; $string =~ s/\s+$//;
-sauoq
"My two cents aren't worth a dime.";
  • Comment on Re: How to eliminate white spaces,tabs,new lines at thestart and end of a long string ??
  • 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 Aristotle (Chancellor) on Nov 24, 2005 at 07:26 UTC

    Or, as I prefer,

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

    Makeshifts last the longest.

      why is that better ?
        To save typing $var =~ multiple times, thus probably reducing the wear & tear of the keyboard & to avoid tediousness.

      Whatever floats your boat... I think that's somewhat less readable, though. But not so much so that I'd complain. I'd expect that doing it without the for would probably be more efficient, so if I found your code in a long loop, I'd likely change it for the more verbose form.

      -sauoq
      "My two cents aren't worth a dime.";
      

        I didn’t suggest it’s better. I prefer it because I find it slightly less noisy and repetitive; as you said, whatever floats one’s boat.

        You’re in trouble if that’s the best opportunity for optimisation you can see, though… :-)

        Makeshifts last the longest.