develooper Front page | perl.perl5.porters | Postings from August 2013

[perl #7624] handling of non-Unix newlines

Thread Previous | Thread Next
From:
James E Keenan via RT
Date:
August 9, 2013 00:03
Subject:
[perl #7624] handling of non-Unix newlines
Message ID:
rt-3.6.HEAD-2552-1376006572-1945.7624-15-0@perl.org
On Tue Sep 04 14:29:26 2001, crowell01@lightandmatter.com wrote:
[snip]
> 
> 	I use Perl on MacOS X, which can use both Unix and non-Unix newlines.
> It seems that when Perl is interpreting a .pm file that contains
> non-Unix newlines, it doesn't do either of the things that, IMHO,
> would be reasonable: (1) complain about non-Unix newlines, or (2)
> treat the non-Unix newlines the same way it would treat Unix
> newlines. Instead, it seems to treat the whole file as if it
> was empty. The result is an error message saying simply that the
> module didn't return a true value, which makes it hard to diagnose
> the problem -- my editor (BBEdit) doesn't show any hint of which
> flavor of newlines a file contains.
> 
> 	I don't know for sure, but my guess is that it thinks the
> whole file is just one long line, i.e. the newlines are interpreted
> as if they were equivalent to blanks or tabs. Since the first line is
> a #/usr/bin/perl comment, the whole file is treated as a comment line.
> 
> 	I don't know if it would be ridiculously hard to make
> Perl agnostic about the flavor of newlines, but I think it might
> make sense for it at least to issue a warning if it detects that the
> whole file contains no Unix newlines whatsoever, but does contain
> a bunch of non-Unix newlines.
> 

And then, on Fri Jul 25 14:37:08 2008, animator wrote:
> This issue is not limited to Mac OS X.
> 
> Example (on linux):
> 
> $ echo -en 'print "1: " . __FILE__;\n# comment\nprint "2: " . 
> __FILE__;\n;1;\n' > Foo_n.pm
> $ perl -MFoo_n -le1
> 1: Foo_n.pm
> 2: Foo_n.pm
> 
> $ echo -en 'print "1: " . __FILE__;\r\n# comment\r\nprint "2: " . 
> __FILE__;\r\n;1;\r\n' > Foo_rn.pm
> $ perl -MFoo_rn -le1
> 1: Foo_rn.pm
> 2: Foo_rn.pm
> 
> 
> $ echo -en 'print "1: " . __FILE__;\r# comment\rprint "2: " . 
> __FILE__;\r;1;\r' > Foo_r.pm
> $ perl -MFoo_r -le1
> 1: Foo_r.pm
> 
> (note the missing 2: Foo_r.pm line)


1. Wouldn't it be more precise to say that this is the result of using
'\r' as the newline character?

$ echo -en 'print "1: " . __FILE__;\r# comment\rprint "2: " .
__FILE__;\r;1;\r' > Foo_r.pm

[# be sure to run above without the formatting imposed by RT ]

$ $ od -c Foo_r.pm 
0000000   p   r   i   n   t       "   1   :       "       .       _   _
0000020   F   I   L   E   _   _   ;  \r   #       c   o   m   m   e   n
0000040   t  \r   p   r   i   n   t       "   2   :       "       .    
0000060   _   _   F   I   L   E   _   _   ;  \r   ;   1   ;  \r
0000076

$ view Foo_r.pm

print "1: " . __FILE__;^M# comment^Mprint "2: " . __FILE__;^M;1;^M

2. Is this something we have to worry about these days?

Thank you very much.
Jim Keenan

---
via perlbug:  queue: perl5 status: open
https://rt.perl.org:443/rt3/Ticket/Display.html?id=7624

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About