Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.

Add a newline to the end of a file

by jmcnamara (Monsignor)
on Nov 28, 2002 at 11:25 UTC ( [id://216282]=CUFP: print w/replies, xml ) Need Help??

Add a missing newline to the end of a file to placate compilers like gcc 3.

gcc 3.x complains if a source or header file doesn't have a newline at the end:
$ gcc -c no_eof.c no_eof.c:9:2: warning: no newline at end of file

The following snippet will fix that for one or more files:     perl -i -pl -eof file1 file2 ...

The following is an alternative approach:     perl -i -pe '$_ .= $/ if eof and not /\n/' file1 file2 ...

Replies are listed 'Best First'.
Re: Add a newline to the end of a file
by PodMaster (Abbot) on Nov 28, 2002 at 13:08 UTC
    Don't know what kind of hacked version of perl you got, but you need to give -i something.

    MJD says you can't just make shit up and expect the computer to know what you mean, retardo!
    ** The Third rule of perl club is a statement of fact: pod is sexy.

      From perlrun:
      -i[extension] ... If no extension is supplied, no backup is made and the current file is overwritten.

      However, on Dos and some other OSes the extension is mandatory. This is due to the fact that these OSes cannot unlink an open file.


      I imagine it's a regular perl, but the platform is something other than Windows.

      See perlrun and the latest p5p digest

      -- simonflk

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://216282]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (2)
As of 2024-06-22 12:34 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.