SOLVED (sort of): perl script prints parts of strings in the wrong order

Colin Watson cjwatson at
Tue Aug 7 08:08:09 UTC 2018

On Tue, Aug 07, 2018 at 08:07:05AM +0200, M. Fioretti wrote:
> On 2018-08-07 07:56, Olivier wrote:
> > According to perl documentation, chomp removes the eding of a line that
> > corresponds to teh current value of $/ so it really depends what you set
> > into $/
> I know that. That is the reason why I was caught off guard. I have become
> so accustomed, for many years, to have $/ = "\r\n" by default on any Linux
> box I worked on, that I thought to anything but a different value for it.

That certainly isn't my memory, and I'd find it extremely surprising for
a Unix build of perl to have $/ set to anything but "\n" by default.  I
really think you're misremembering something here.

Perhaps you're used to doing file I/O via the :crlf layer (see
PerlIO(3perl)), which would convert raw \r\n to \n when reading it from
files?  But on Unix you'd have to be a bit careful to apply that only on
input, not output.

A quick web search finds plenty of old posts asking similar questions,
indicating that this isn't a recent change.  For instance:

> Of course, my memory may very well fail me on this. At this point, mine
> is just a curiosity like "did $/ change at some point in Ubuntu, or better:
> in Perl as packaged for Ubuntu?" But just an unimportant curiosity, really,
> no need to reply unless you really have the answer on the top of your
> head.

I don't have any properly old environments to hand right now, but at
least Debian 7 and Ubuntu 12.04 behaved the same way.  A quick test

  $ perl -e '$_ = "foo\r\n"; chomp; print' | od -tx1
  0000000 66 6f 6f 0d

Colin Watson                                       [cjwatson at]

More information about the ubuntu-users mailing list