Question : Using perl, I need to check if all the files in a certain directory start with a certain character string.

I am looking in $dir1, and all the files need to start with EDI322.
I tried getting substrings of the files using substr(@files,0,6) and using an == to match to a hard coded variable but it's not working if no files exist.

Answer : Using perl, I need to check if all the files in a certain directory start with a certain character string.

maybe something like this then...

my $found = 0;
foreach my $file (@files) {
    if( substr($file, 0, 6) eq 'EDI322' ) {
       print "Exist\n";
       $found++;
    }
}
if( ! $found ) {
   print "=======The output file does not exist ==========\n";
   print LOG "=======The output file does not exist ==========\n";
   print Comp_LOG "NS LF Download Process failed\n";
   die;
}


Then again if all you want to know if whether @files has no files starting with EDI322, try this:
if( ! grep(/^EDI322/, @files) ) {
   print "=======The output file does not exist ==========\n";
   print LOG "=======The output file does not exist ==========\n";
   print Comp_LOG "NS LF Download Process failed\n";
   die;
}

Good luck!
Random Solutions  
 
programming4us programming4us