in reply to Reading and writing to files
i have two files "daily.txt" and "monthly.txt". they are both in CSV format. how will i be able to read the last 3 lines of daily.txt and write those 3 lines in front of monthly.txt then remove those 3 lines from daily.txt. thanks in advance(And the posting from Corion fails to rewrite "daily.txt", thus leading me to write the following:)
Untested code follows:
local $/; # make undef my @daily = do { local @ARGV = "daily.txt"; <> }; my @monthly = do { local @ARGV = "monthly.txt"; <> }; die "nothing to transfer" unless @daily > 3; my @transfer = splice @daily, -3; # last three of @daily becomes @tran +sfer open OUT, ">daily.txt" or die "Cannot recreate daily.txt: $!"; print OUT @daily; close OUT; open OUT ">monthly.txt" or die "Cannot recreate monthly.txt: $!"; print OUT @transfer, @monthly; close OUT;
-- Randal L. Schwartz, Perl hacker
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Reading and writing to files: Debrief Question v2
by THuG (Beadle) on Aug 09, 2000 at 16:43 UTC | |
by cmburns (Acolyte) on Aug 09, 2000 at 17:10 UTC | |
|
RE: Re: Reading and writing to files
by boo_radley (Parson) on Aug 09, 2000 at 18:04 UTC | |
by ChuckularOne (Prior) on Aug 09, 2000 at 19:11 UTC |