in reply to How check whether csv file with header is empty file or not in perl

Try this:
use Modern::Perl; say 'Empty file' if 1 == scalar grep {/[^\s,]/} <DATA>; __DATA__ header1, header2, header3 ,,,,,,, , , , , , ,
This will say "Empty file" if the file only contains a header line plus optionally empty lines or lines with nothing but whitespace and comma's.

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

My blog: Imperial Deltronics
  • Comment on Re: How check whether csv file with header is empty file or not in perl
  • Download Code

Replies are listed 'Best First'.
Re^2: How check whether csv file with header is empty file or not in perl
by hi123 (Initiate) on Sep 06, 2012 at 11:07 UTC
    Hi...where should i include ur line in my script,pls advise
      Here it is:
      use Modern::Perl; open(my $data, '<', $file_c) or die "Could not open '$file_c' $!"; say 'Empty file' if 1 == scalar grep {/[^\s,]/} <$data>;

      CountZero

      A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      My blog: Imperial Deltronics