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
In reply to Re: Reading and writing to files
by merlyn
in thread Reading and writing to files
by damian
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |