in reply to text file validation
my $fileSize = -s $fileName;
or by using the stat() built-in
my $fileSize = (stat $fileName)[7];
then you can decide how many bytes (always assuming characters are bytes) to read
my $limit = 160; my $bytesToRead = $fileSize > $limit ? $limit : $fileSize;
then use read() to read in what is appropriate (being sure to test for a successful read) and print it
my $bytesRead = read($inpFH, my $inpBuffer, $bytesToRead); die qq{Bad read: read $bytesRead, expected $bytesToRead\n} unless $bytesRead == $bytesToRead; print $inpBuffer;
I haven't shown getting and validating the file name or the opening and closing of filehandles here.
I hope this is of use.
Cheers,
JohnGG
|
|---|