in reply to term in last line of flatfile

I presume you want to skip the first line right? Thats what the
next until $. >1;
is supposed to do? Except it doesnt. :-) until != unless. Also it isnt the best way to remove the first line, as it puts a conditional inside a loop that need not be.

Then you have a problem with

next if $_ = /^done/;
which is exactly equivelent to
next if $_= $_=~/^done/;
Which isnt what you want at all. In addition I question whether that should really be last and not next. So I would say it should be
last if /^done/; #or #last if $_=~/^done/;
But by the time I get to this point I reckon that you are trying to put all but the first and the (ostensibly) last record in the file into an array, skipping blank lines. If so I would write it as
my @contents; my $header=<PAST>; # extract the first line while (<PAST>) { next unless /\S/; # ignore whitespace only lines. last if /^done/; # finish when we hit a line starting with 'done +' #chomp; # uncomment if you dont want newlines in conten +ts. push @contents,$_; # add the line to the buffer }
UPDATE:

Assuming that the done line also contains a count then you may want to check that it matches with

my @contents; my $header=<PAST>; # extract the first line while (<PAST>) { next unless /\S/; # ignore whitespace only lines. if (/^done,(\d+)$/) { die "Count mismatch in trailer. Got $1 expected @{[scalar @con +tents]}" unless $1 == scalar(@contents); last; } #chomp; # uncomment if you dont want newlines in conten +ts. push @contents,$_; # add the line to the buffer }
HTH

--- demerphq
my friends call me, usually because I'm late....

Replies are listed 'Best First'.
Re: Re: term in last line of flatfile
by alexiskb (Acolyte) on Oct 11, 2002 at 08:41 UTC
    Great! that handles it perfectly, no errors at all.. thank you very much indeed... you are most kind, you were quite right i did have a header also! cheers!