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

Or, as I prefer,

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

Makeshifts last the longest.

  • Comment on Re^2: How to eliminate white spaces,tabs,new lines at thestart and end of a long string ??
  • Download Code

Replies are listed 'Best First'.
Re^3: How to eliminate white spaces,tabs,new lines at thestart and end of a long string ??
by Anonymous Monk on Nov 24, 2005 at 09:01 UTC
    why is that better ?
      To save typing $var =~ multiple times, thus probably reducing the wear & tear of the keyboard & to avoid tediousness.
Re^3: How to eliminate white spaces,tabs,new lines at thestart and end of a long string ??
by sauoq (Abbot) on Nov 24, 2005 at 18:02 UTC

    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.

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

        Actually, I think I'm probably doing quite well if that's the best opporturnity for optimization. ;-)

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