http://qs321.pair.com?node_id=7175


in reply to Writing to files

I've got a program online that does insertion into a file (http://www.pobox.com/~japhy/tmp/perl/add_lines). But the bigger question is, WHY DO YOU NEED TO DO THIS? Observe:
open FILE, ">>data" or die "can't append to data: $!"; print FILE "NEW RECORD\n"; close FILE; # now, to store the file's contents in an array, MOST # RECENT DATA FIRST, use unshift instead of push! open FILE, "data" or die "you know the drill... $!"; unshift @contents, $_ while <FILE>; close FILE;