perlsyntaxperl4

How do I chomp a string if I have Perl 4?


I am writing a script on my personal machine which is connected to the remote server. I think the remote server has Perl 4.0 or lesser version installed and that is why it is unable to recognize the same. Is there an alternative to the chomp command?


Solution

  • It's not an exact replacement, but you could try:

    $var =~ s/\r?\n?$//
    

    which will strip either CRLF (DOS), LF (Unix), CR (Mac?).

    The normal chomp operator always strips out the currently defined $INPUT_RECORD_SEPARATOR for the current O/S.