in reply to Re: help with REGEXP to remove carriage return and caret from end
in thread help with REGEXP to remove carriage return and caret from end

Not such a smart thing generally. Chop will remove the last character regardless of what it was. If it was a multiple character sequence then you have stuffed things for chomp - it won't remove the mutliated line end sequence. If it was a single character then the chomp is not required. In neither case is chomp going to do anything useful following chop.

chomp first to remove the line end sequence (which may comprise many characters if $/ has been altered) and then chop if you really want to always remove the last character (doesn't happen often actually).


DWIM is Perl's answer to Gödel
  • Comment on Re^2: help with REGEXP to remove carriage return and caret from end

Replies are listed 'Best First'.
Re^3: help with REGEXP to remove carriage return and caret from end
by CountZero (Bishop) on Jul 25, 2006 at 21:44 UTC
    I don't agree. From the OP's example it is clear his string is built as follows: 'some_name' + 'EOL-character(s)' + '^'.

    chop removes the '^' and then chomp can do its usual job of handling the 'EOL-character(s)'.

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

      The key word in my reply however was "generally" in the first sentence. Generally, as elaborated in my previous reply, chop is not such a useful function.

      Oh, I agree that it works for OP's problem as stated. But it is a fragile solution. Very likely that doesn't matter in OP's case. But in the interests of general education it is worth noting that chop is unfussy about what it removes and that chomp only removes trailing contents matching $/, and that $/ may contain anything.


      DWIM is Perl's answer to Gödel
        OK, in that case I generally agree with you! :-)

        CountZero

        "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law