in reply to How do I truncate a flat file, then append to front?

1) After you read in, do a chomp on each line;
2)When you write out, do print LOG join("\n", @old_logfile)
3) @old_logfile = @logfile[0 .. 100] is not safe, as you may have less than 100 lines at the beginning.

Replies are listed 'Best First'.
Re: Re: How do I trauncate a flat file, then append to front?
by pg (Canon) on Nov 16, 2002 at 05:29 UTC
    For the third point, you can do:
    @old_logfile = @logfile[0..($#logfile > 99 ? 100 : $#logfile)];
Re: Re: How do I trauncate a flat file, then append to front?
by pg (Canon) on Nov 16, 2002 at 08:40 UTC
    For point 1 and 2, you actually don't need to chomp the new lines away, and then add them back. Those blanks you got at the beginning of the lines, starting from the second line from the old file, is $LIST_SEPARATOR, and default value is space. You can do this:
    use English; $LIST_SEPARATOR = "";