Jan 2, 2007 #1 sun9 Programmer Joined Dec 13, 2006 Messages 31 Location 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.
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.
Jan 2, 2007 #2 KevinADC Technical User Joined Jan 21, 2005 Messages 5,070 Location US 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! Upvote 0 Downvote
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!
Jan 2, 2007 #3 spookie Programmer Joined May 30, 2001 Messages 655 Location IN 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. Upvote 0 Downvote
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.
Jan 11, 2007 Thread starter #4 sun9 Programmer Joined Dec 13, 2006 Messages 31 Location US If the data is present in the file what will be the value of scalar @data ? Upvote 0 Downvote
Jan 11, 2007 #5 KevinADC Technical User Joined Jan 21, 2005 Messages 5,070 Location US If the data is present in the file what will be the value of scalar @data ? Click to expand... that will be the number of lines in the file. A value of 0 (zero) indicates there are no lines. - Kevin, perl coder unexceptional! Upvote 0 Downvote
If the data is present in the file what will be the value of scalar @data ? Click to expand... that will be the number of lines in the file. A value of 0 (zero) indicates there are no lines. - Kevin, perl coder unexceptional!
Jan 12, 2007 Thread starter #6 sun9 Programmer Joined Dec 13, 2006 Messages 31 Location US ok thanks. Upvote 0 Downvote