in reply to whitespace eliminator for arrays

You can get some more efficient by writing s/\s+//g for @array; Disregarding locales, the following is best: tr/\x09\x0A\x0C\x0D\x20//d for @array;

Makeshifts last the longest.

Replies are listed 'Best First'.
Re**2: whitespace eliminator for arrays
by belg4mit (Prior) on Oct 22, 2002 at 18:59 UTC
    That also ignores Unicode. A slightly more complete substitution would be
    =~ s/[[:space:]]//g

    --
    perl -wpe "s/\b;([mnst])/'$1/g"

      Or, of course, s/[[:space:]]+//g; ;-)

      Makeshifts last the longest.

Re: Re: whitespace eliminator for arrays
by markcsmith (Novice) on Oct 22, 2002 at 19:24 UTC
    Out of curiosity, why would specifiying the hex for each type of whitespace and using tr be better than a s///? Also, how does putting the for after the statement increase efficiency? Not that I'm nagging, I'm curious.

      You missed the little + I added to the regex. :-) Using for as expression modificator wasn't the point. The + will cause the regex to delete sequences of whitespace in one fell swoop, rather than character by character.

      tr is better in that it doesn't fire up the entire regex engine to do its job. It's therefor more efficient for the specific job of deleting all of a list of characters from a string. However, it doesn't understand classes like \s as the regex engine does, so you have to spell out all the characters. Doing so with hex codes is merely one choice out of several.

      Makeshifts last the longest.

        I see. Thanks for the reply.