in reply to Stripping characters from strings

You could do something like
s/.$//g;
This means: substitute(s/) any one character(.) counting from the end ($) with nothing (//) and at all possible matches(g).

Replies are listed 'Best First'.
RE: Re: Stripping characters from strings
by elwarren (Priest) on Oct 30, 2000 at 04:07 UTC
    Is the g needed in this case? Wouldn't this only match the end of line once?
      With an anchor that isn't within an alteration, "g" is pretty useless. I'm not near a perl with Debugging turned on so I can't tell you if it's a no-op, but I do know it isn't a dangerous thing to have on there, just useless. =)

      Update... And what merlyn said below. (yeesh $*)

      --
      $you = new YOU;
      honk() if $you->love(perl)

        Actually, if $* is 1, then $ matches any embedded newline as well as the end of the string, so s/.$//g; actually makes sense!

        I doubt that was the case here, though. {grin}

        -- Randal L. Schwartz, Perl hacker