How do I get Perl to die after reading the 1st line in a file?

tim85a

New member
I've got a program that reeds the first line from a file then deletes it (code below).


open (line, "list.txt") || die ("Could not open file $!");
$data = <line>;
close (line);

print "The first line of the file reads : $data ";

open INFILE, '<list.txt';
open OUTFILE, '>temp.txt';
<INFILE>; #discards first line
print OUTFILE $_ while (<INFILE>);
close OUTFILE;
close INFILE;

rename("temp.txt", "list.txt") || die ( "Error in renaming" );

What I can't do, is get the program to die when the list is empty. I'm guessing I could get it to see if $data is more than 1 letter long?? But I don't know how to do that or where to put it in the code.

Thanks for your help.
 
Back
Top