in reply to How to delete the line I have just read?

More details on what seems to be a trivial operation: http://perl.plover.com/yak/lightweight-db/

You can get fancy with core module Tie::File

Or, you can "reverse" your method and have your script print out the remaining files when it encounters the first failure.
  • Comment on Re: How to delete the line I have just read?

Replies are listed 'Best First'.
Re^2: How to delete the line I have just read?
by ademmler (Novice) on Aug 05, 2008 at 08:00 UTC
    Hi to all, thanks for your answers. While you have been answering I was on the search for a solution by myself and I have found one. The major part for me is the change should be saved imedeatly to the file - after deleteing the line, because I need to have the actual status saved in the file even if the script crashes. And I did not want to ope/close/reoepn the file while each loop. I have found also Tie::File and with a litle trick it does exactly what I want.

    #!/usr/bin/perl
    use strict;
    use Tie::File;

    tie my @list, 'Tie::File', $list or die "Can't open list of files as array\n";

    my $records = @list;
    print"## Start: Found $records records in $list ##\n";

    my ($count, $counter);

    for ($count = 0; $count < $records; $count++ ) {
    #The important part ist to keep [0] here because it uses always the first line
    my $file = $list[0];
    #do some processing with the file from record. . .
    #delete line
    shift(@list) or die "Can't delete record $file in $list\n";
    }
    Regards Alex