Prepending to a file

Discussion in 'Perl Misc' started by Dave, Jul 24, 2005.

  1. Dave

    Dave Guest

    I would like to write something at the begginging of a text file,
    without overwriting what is already there.

    i.e if the file 'foo' contains

    two
    three
    four

    I would like to be able to prepend 'one'

    so the file reads

    one
    two
    three
    four

    How is the best way to do this?

    On a UNIX sheel script I could do it by writing the new data (in this
    case the word 'one') into another file, then using cat

    But I am not sure how to do any of this in perl. I'm using a UNIX
    system, and Perl 5.8.6
    Dave, Jul 24, 2005
    #1
    1. Advertising

  2. Gunnar Hjalmarsson, Jul 25, 2005
    #2
    1. Advertising

  3. Dave

    Guest

    Dave wrote:

    > I would like to write something at the begginging of a text file,
    > without overwriting what is already there.


    See FAQ.
    , Jul 25, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stefan Behnel

    Prepending to traceback

    Stefan Behnel, Feb 2, 2005, in forum: Python
    Replies:
    3
    Views:
    310
    Ian Bicking
    Feb 9, 2005
  2. Serdar Kýlýç

    Array prepending nil object

    Serdar Kýlýç, Jan 31, 2006, in forum: Ruby
    Replies:
    3
    Views:
    102
    Serdar Kýlýç
    Jan 31, 2006
  3. Thomas Murphy

    Prepending string "@" to usernames

    Thomas Murphy, May 24, 2013, in forum: Python
    Replies:
    0
    Views:
    85
    Thomas Murphy
    May 24, 2013
  4. Dan Stromberg

    Re: Prepending string "@" to usernames

    Dan Stromberg, May 25, 2013, in forum: Python
    Replies:
    0
    Views:
    84
    Dan Stromberg
    May 25, 2013
  5. Thomas Murphy

    Re: Prepending string "@" to usernames

    Thomas Murphy, May 25, 2013, in forum: Python
    Replies:
    0
    Views:
    74
    Thomas Murphy
    May 25, 2013
Loading...

Share This Page