Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Prepending to a file

Reply
Thread Tools

Prepending to a file

 
 
Dave
Guest
Posts: n/a
 
      07-24-2005
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

 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      07-24-2005
Dave wrote:
> I would like to write something at the begginging of a text file,
> without overwriting what is already there.


<snip>

> 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.


http://perldoc.perl.org/perlintro.html

http://learn.perl.org/

Happy reading!

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
 
 
 
nobull@mail.com
Guest
Posts: n/a
 
      07-25-2005
Dave wrote:

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


See FAQ.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
BGP prepending and local preference question J Cisco 3 08-29-2006 10:09 PM
Redist. OSPF into BGP -- matching and prepending Christopher Heer Cisco 5 03-22-2006 11:27 AM
Array prepending nil object Serdar Kl Ruby 3 01-31-2006 06:26 AM
An Automated process of watching a network file folder, reading a file in it and deleting the file using ASP.NET ? Luis Esteban Valencia Muoz ASP .Net 3 06-04-2005 10:56 AM
Prepending to traceback Stefan Behnel Python 3 02-09-2005 05:01 PM



Advertisments