Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > how to write text to a file

Reply
Thread Tools

how to write text to a file

 
 
Mark Tarver
Guest
Posts: n/a
 
      12-17-2006
How to you append text to a file in Perl?

Mark

 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      12-17-2006
Mark Tarver wrote:
> How to you append text to a file in Perl?


open my $append_fh, '>>', 'file.txt' or die "Cannot open file.txt for
append: $!";
print $append_fh "This text appears at the bottom of file.txt\n";
close $append_fh;

See also:
perldoc -f open
perldo perlopentut

Paul Lalli

 
Reply With Quote
 
 
 
 
Uri Guttman
Guest
Posts: n/a
 
      12-17-2006
>>>>> "PL" == Paul Lalli <(E-Mail Removed)> writes:

PL> Mark Tarver wrote:
>> How to you append text to a file in Perl?


PL> open my $append_fh, '>>', 'file.txt' or die "Cannot open file.txt for
PL> append: $!";
PL> print $append_fh "This text appears at the bottom of file.txt\n";
PL> close $append_fh;

PL> See also:
PL> perldoc -f open
PL> perldo perlopentut

and also File::Slurp has a append_file() sub which is perfect for this.

uri

--
Uri Guttman ------ http://www.velocityreviews.com/forums/(E-Mail Removed) -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
 
Reply With Quote
 
Mark Tarver
Guest
Posts: n/a
 
      12-17-2006

Mark Tarver wrote:
> How to you append text to a file in Perl?
>
> Mark


Thanks for all this. I've got a working version now.

Mark

 
Reply With Quote
 
Marc Espie
Guest
Posts: n/a
 
      12-17-2006
In article <em486a$8v$(E-Mail Removed)-halle.de>,
Mirco Wahab <(E-Mail Removed)> wrote:
> use IO::File;
>
>which some people do consider "more contemporary" ...


Only some... IO::File is heavy, and incurs some real penalty for light-weight
scripts (the overhead of loading File::IO is anything but trivial)

When auto-vivification of file handles became available, I ditched IO::File
almost completely. I very often do not actually need to have any of the OO
properties of IO::File (Plus, the print $fh syntax matches the second way
to call object methods anyways).

Some people may see it as slightly more readable and less funky, and as far
as I know, perl6 will have a clearer syntax than open(my $f, '>', something);
but apart from that, it's just fine and *fast* in 99% of the cases.
 
Reply With Quote
 
Arved Sandstrom
Guest
Posts: n/a
 
      12-18-2006
"Uri Guttman" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
>>>>>> "MT" == Mark Tarver <(E-Mail Removed)> writes:

>
> MT> Mark Tarver wrote:
> >> How to you append text to a file in Perl?
> >>
> >> Mark

>
> MT> Thanks for all this. I've got a working version now.
>
> thanks for your own question? why would you followup to that and not
> some answer? kinda silly IMO.


Seems pretty logical if all or most of the answers were helpful. By
selecting a specific answer you're making another statement, that that
answer was especially helpful. And maybe you don't want to leave that
impression either.

AHS


 
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
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
When using System.IO.FileStream, I write 8 bytes, then seek to the start of the file, does the 8 bytes get flushed on seek and the buffer become a readbuffer at that point instead of being a write buffer? DR ASP .Net 2 07-29-2008 09:50 AM
When using System.IO.FileStream, I write 8 bytes, then seek to the start of the file, does the 8 bytes get flushed on seek and the buffer become a readbuffer at that point instead of being a write buffer? DR ASP .Net Building Controls 0 07-29-2008 01:37 AM
is better to open, write, close file than open, write, append, close? Iulian Ilea Javascript 1 12-21-2006 04:32 PM
python+windows/linux -> write stdout text to always on top text? flamesrock Python 5 05-04-2005 06:34 PM



Advertisments