Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

empty data file check

Status
Not open for further replies.

sun9

Programmer
Dec 13, 2006
31
US
Hi,

I am using the tie module to read the contents of a file as such-

tie my @data, 'Tie::File', $file ;

How do I go about checking if there is no data in the file?

thanks.
 
just like you would with any array:

Code:
if (scalar @data == 0) {
   "there is no data";
}

or:

Code:
unless (@data) {
   "there is no data";
}

- Kevin, perl coder unexceptional!
 
Alternatively you can filter on filesize.
Code:
my $filesize = -s $filename;
if ( $filesize == 0 )
{
   print "Empty file!!" ;
}

--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
If the data is present in the file what will be the value of scalar @data ?
 
If the data is present in the file what will be the value of scalar @data ?

that will be the number of lines in the file. A value of 0 (zero) indicates there are no lines.

- Kevin, perl coder unexceptional!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top