Perl source with DOS newlines on unix 
Author Message
 Perl source with DOS newlines on unix

I've got a user who appears to be editing Perl source via a Samba
server using a DOS-style editor (i,e the source code contains CR
control characters at the end of every line), and they're running this
very source file on a unix-based web server as a CGI script.

Their shebang line reads

#!/usr/bin/perl --

and I assume the "--" is a trick to hide the CR character.

I'm not sure whether I should be trying to persuade this user to
change their ways.  Are there any deleterious effects to be expected
from running such source code in unix?  What, for example, if a
here-document is used - are the CR characters considered to be part of
the data?  It appears not, by running a test (in other words it seems
to DWIM), but I'm not sure why that should be so.

Is there an official line on this, please?

--



Sat, 11 Dec 2004 20:47:59 GMT  
 Perl source with DOS newlines on unix
In article


Quote:
> I've got a user who appears to be editing Perl source via a Samba
> server using a DOS-style editor (i,e the source code contains CR
> control characters at the end of every line), and they're running this
> very source file on a unix-based web server as a CGI script.

All good editors should allow you to save with whatever line-endings you
want, and file serving software should not force line-ending translation
on you (i.e. it should be an option) for text files.

So my personal view is to use the right line endings for the target
system - in this case a Windows program should save the file with Unix
line endings. Not that perl seems to mind (as I see you've been trying
to find out) but I'm sure it can bite you in interesting ways. Either
that or quietly change their samba settings to translate line endings
for .pl files :-)

FWIW, perl on the Mac (using MacPerl 5.6.1) doesn't seem too fussy about
the line endings in modules, although it's not happy with Unicode
(except UTF-8 encoded, and not using the unicode line breaks). I guess
perl does what you mean usually.

P

--
pkent 77 at yahoo dot, er... what's the last bit, oh yes, com
Remove the tea to reply



Sat, 11 Dec 2004 22:07:56 GMT  
 Perl source with DOS newlines on unix

Quote:
> All good editors ...

my guess is that Alan can't control what editor someone decides to use. :)

Quote:
> FWIW, perl on the Mac (using MacPerl 5.6.1) doesn't seem too fussy about
> the line endings in modules, although it's not happy with Unicode
> (except UTF-8 encoded, and not using the unicode line breaks). I guess
> perl does what you mean usually.

Perl on MacOS X does seem to care.  it sees one long shebang line which is
effectively a null script.  so, no errors. :(

that use to bother me until i fixed BBEdit's preferences.

--

The Perl Review - a new magazine devoted to Perl
<http://www.theperlreview.com>



Sat, 11 Dec 2004 22:36:05 GMT  
 Perl source with DOS newlines on unix
On Jun 25, pkent inscribed on the eternal scroll:

Quote:
> > I've got a user who appears to be editing Perl source via a Samba
> > server using a DOS-style editor
...
> All good editors should allow you to save with whatever line-endings you
> want,

Sure, when I'm editing on Windows I use PFE32, but that wasn't the
question.

Quote:
> and file serving software should not force line-ending translation
> on you (i.e. it should be an option) for text files.

Samba servers, at least the way I've seen them run, have no
distinction between binary stuff and text. They just deliver the
bytes.  This is, of course, sometimes a problem, but there's no magic
wand.

PCNFS had two quite separate mount modes so if you mixed binary and
text in the same filesystem (as one does in unix) then you had to
mount the filesystem twice over, once in binary and once in text mode,
and remember to reference the correct one.  Mumble.

Quote:
> So my personal view is to use the right line endings for the target
> system

Mine too, for sure.

The question I'm raising is about whether to interfere with this
user's present habits.

Quote:
> Not that perl seems to mind (as I see you've been trying
> to find out) but I'm sure it can bite you in interesting ways.

Seems as if I may be due to find out...

Quote:
> that or quietly change their samba settings to translate line endings
> for .pl files :-)

That's a new one on me...

Nono, this chap will be continuing work on his scripts on a system
that's 8 timezones away and very much not under my control.

all the best



Sat, 11 Dec 2004 23:05:32 GMT  
 Perl source with DOS newlines on unix

Quote:

> On Jun 25, pkent inscribed on the eternal scroll:

> > > I've got a user who appears to be editing Perl source via a Samba
> > > server using a DOS-style editor
> ...
> > All good editors should allow you to save with whatever line-endings you
> > want,

> Sure, when I'm editing on Windows I use PFE32, but that wasn't the
> question.

s/<snip>//

So why not have this user use FTP, or is that not an option? I can't
think of any way to force the way it's transferred via Samba (but I
don't really use that much/ever either).

Regards,
Robert
--

Server administrator/support - 2Host.com web hosting.
Secure, reliable hosting - What you expect & deserve!
How are we different? Find out: http://www.2host.com/



Sat, 11 Dec 2004 23:39:02 GMT  
 Perl source with DOS newlines on unix


Quote:


> > FWIW, perl on the Mac (using MacPerl 5.6.1) doesn't seem too fussy about
> > the line endings in modules, although it's not happy with Unicode
> > (except UTF-8 encoded, and not using the unicode line breaks). I guess
> > perl does what you mean usually.

> Perl on MacOS X does seem to care.  it sees one long shebang line which is
> effectively a null script.  so, no errors. :(

> that use to bother me until i fixed BBEdit's preferences.

hmm, does OS X perl (i.e. proper command-line Unixy perl) mind if .pm
files have incorrect line breaks in them?

Just asking because, for however many years I've been moving files from
one platform to another, I've been bitten and annoyed by the 3 different
styles of line breaks in the world... many many times.

P

--
pkent 77 at yahoo dot, er... what's the last bit, oh yes, com
Remove the tea to reply



Sun, 12 Dec 2004 03:43:19 GMT  
 Perl source with DOS newlines on unix

Quote:

>I've got a user who appears to be editing Perl source via a Samba
>server using a DOS-style editor (i,e the source code contains CR
>control characters at the end of every line), and they're running this
>very source file on a unix-based web server as a CGI script.

>Their shebang line reads

>#!/usr/bin/perl --

>and I assume the "--" is a trick to hide the CR character.

>I'm not sure whether I should be trying to persuade this user to
>change their ways.  Are there any deleterious effects to be expected
>from running such source code in unix?  What, for example, if a
>here-document is used - are the CR characters considered to be part of
>the data?  It appears not, by running a test (in other words it seems
>to DWIM), but I'm not sure why that should be so.

Perhaps it was designed to DWIM?

Scripts ignoring CR in source code is a fairly recent addition. This is
what perldelta for 5.005 says about it:

<http://www.perl.com/doc/manual/html/pod/perldelta.html#More_generous_...>

Quote:

        Inside string literals and here documents, literal carriage
        returns are ignored if they occur paired with newlines, or get
        interpreted as newlines if they stand alone.

Does that answer your question?

But perhaps, on Unix, you could still get in trouble with CR's in the
DATA section.

Ah, yes, indeed. If you do

        while(<DATA>) {
            print;
        }
        __DATA__
        alpha
        beta
        gamma

then it turns out that the produced output when redirected to a file, is
indeed a DOS text file.

So it's not 100% OK. Not that producers of HTML pages care, quite a
*lot* of all web pages on Internet contain two CR's per LF.

--
        Bart.



Sun, 12 Dec 2004 09:15:50 GMT  
 Perl source with DOS newlines on unix
On Jun 26, Bart Lateur inscribed on the eternal scroll:

Quote:
> <http://www.perl.com/doc/manual/html/pod/perldelta.html#More_generous_...>

> Quote:

>    Inside string literals and here documents, literal carriage
>    returns are ignored if they occur paired with newlines, or get
>    interpreted as newlines if they stand alone.

Aha, well spotted.  Thanks, must admit I had missed that.

Quote:
> Does that answer your question?

I think it does, yes.

[issue with DATA noted, thanks]

Quote:
> So it's not 100% OK. Not that producers of HTML pages care, quite a
> *lot* of all web pages on Internet contain two CR's per LF.

I guess that's why HTML source 'found in the wild' quite often gives
the impression of being double-spaced.

cheers



Sun, 12 Dec 2004 10:34:28 GMT  
 Perl source with DOS newlines on unix
hhmm... NO WONDER i've been bit so many times....  3 different styles of
line breaks???

I know <lf><cr>, and <cr>    (ok, it's a vms editor i use sometimes..)

what's the other one?

Quote:





> > > FWIW, perl on the Mac (using MacPerl 5.6.1) doesn't seem too fussy about
> > > the line endings in modules, although it's not happy with Unicode
> > > (except UTF-8 encoded, and not using the unicode line breaks). I guess
> > > perl does what you mean usually.

> > Perl on MacOS X does seem to care.  it sees one long shebang line which is
> > effectively a null script.  so, no errors. :(

> > that use to bother me until i fixed BBEdit's preferences.

> hmm, does OS X perl (i.e. proper command-line Unixy perl) mind if .pm
> files have incorrect line breaks in them?

> Just asking because, for however many years I've been moving files from
> one platform to another, I've been bitten and annoyed by the 3 different
> styles of line breaks in the world... many many times.

> P

> --
> pkent 77 at yahoo dot, er... what's the last bit, oh yes, com
> Remove the tea to reply



Sun, 12 Dec 2004 13:41:42 GMT  
 Perl source with DOS newlines on unix

Quote:

>hhmm... NO WONDER i've been bit so many times....  3 different styles of
>line breaks???

>I know <lf><cr>, and <cr>    (ok, it's a vms editor i use sometimes..)

>what's the other one?

Heh?

If <cr> is chr(13), <lf> is chr(10) (on Ascii... does that include VMS?)
then the "normal" line breaks are

        <cr><lf>            DOS
        <lf>              Unix

and then there is

        <cr>              Macintosh

--
        Bart.



Sun, 12 Dec 2004 13:52:28 GMT  
 Perl source with DOS newlines on unix

Quote:

> hhmm... NO WONDER i've been bit so many times....  3 different styles of
> line breaks???

> I know <lf><cr>, and <cr>    (ok, it's a vms editor i use sometimes..)

> what's the other one?

Doesn't Apple use only CRs?

--
Josef M?llers (Pinguinpfleger bei FSC)
        If failure had no penalty success would not be a prize
                                                -- T.  Pratchett



Sun, 12 Dec 2004 13:55:25 GMT  
 Perl source with DOS newlines on unix
Hey, Bart, Josef, thanks!!!!!

Yep, it's the same on VMS, it's ascii after all anyhow..

Quote:


> >hhmm... NO WONDER i've been bit so many times....  3 different styles of
> >line breaks???

> >I know <lf><cr>, and <cr>    (ok, it's a vms editor i use sometimes..)

> >what's the other one?

> Heh?

> If <cr> is chr(13), <lf> is chr(10) (on Ascii... does that include VMS?)
> then the "normal" line breaks are

>         <cr><lf>                DOS
>         <lf>            Unix

> and then there is

>         <cr>            Macintosh

> --
>         Bart.



Sun, 12 Dec 2004 14:01:37 GMT  
 Perl source with DOS newlines on unix

Quote:
> I've got a user who appears to be editing Perl source via a Samba
> server using a DOS-style editor (i,e the source code contains CR
> control characters at the end of every line), and they're running this
> very source file on a unix-based web server as a CGI script.
> Their shebang line reads
> #!/usr/bin/perl --
> and I assume the "--" is a trick to hide the CR character.

if the CR doesn't effect the program in other ways (only
the DATA section like somebody else said) then it
might be useful to create a perl-binary named
"/usr/bin/perl\r" =)

then there's no more need for the "--" trick...

but i'd say it's better to get users uploading files
with correct line endings than doing such
workarounds...
hth, tina

--
http://www.tinita.de         \  enter__| |__the___ _ _ ___
http://Movies.tinita.de/      \     / _` / _ \/ _ \ '_(_-< of
http://PerlQuotes.tinita.de/   \    \ _,_\ __/\ __/_| /__/ perception



Sun, 12 Dec 2004 15:06:56 GMT  
 Perl source with DOS newlines on unix

Quote:

>> and I assume the "--" is a trick to hide the CR character.

>if the CR doesn't effect the program in other ways (only
>the DATA section like somebody else said) then it
>might be useful to create a perl-binary named
>"/usr/bin/perl\r" =)

>then there's no more need for the "--" trick...

Assuming "\r" doesn't pull tricks on Perl command line options on the
shebang line, then there's no need for that trick: just use

        #!/usr/bin/perl -w

You ought to enable warnings, anyway...   :-)

--
        Bart.



Sun, 12 Dec 2004 15:25:19 GMT  
 Perl source with DOS newlines on unix

Quote:




> > > FWIW, perl on the Mac (using MacPerl 5.6.1) doesn't seem too fussy about
> > > the line endings in modules,
> > Perl on MacOS X does seem to care.  it sees one long shebang line which is
> > effectively a null script.  so, no errors. :(
> hmm, does OS X perl (i.e. proper command-line Unixy perl) mind if .pm
> files have incorrect line breaks in them?

in my experience with perl5.6.1 it does.  if i start with a unix-ish tool
like vim, i don't have a problem.  when i started with BBEdit, it did
Mac-ish sorts of things until i adjusted its preferences to do unix-ish
sorts of things.

the most curious result was reports from Test::Harness that the .t files
contained no code. :)

--

The Perl Review - a new magazine devoted to Perl
<http://www.theperlreview.com>



Sun, 12 Dec 2004 17:07:43 GMT  
 
 [ 25 post ]  Go to page: [1] [2]

 Relevant Pages 

1. How does Perl handle DOS newlines?

2. How to use newlines in DOS command options

3. dos & newline

4. Source for Dos perl

5. UUencoding between UNIX and PC - newlines

6. UUencoding between UNIX and PC - newlines

7. $\ on Win95 - can't get unix newline

8. Installation Instructions of Perl Source files on Unix

9. Using Unix SOURCE in PERL SYSTEM?? NEED HELP

10. Compatabilty of Perl between DOS and Unix

11. need: unix->dos fn conversion perl script

12. Perl to convert DOS commands inside Unix !!!!!!

 

 
Powered by phpBB® Forum Software