Thursday, November 24, 2022

Check the existence of multiple files using array in perl

                                          

 use strict;

use warnings;

#disabling output buffering

$|=1;


sub main{

my @files=('./a.txt','./b.txt','./c.txt',);

#my $file='./a.txt';

foreach my $file(@files){

print "$file\n";


if(-f $file)

{

print "$file exists\n";


}

else

{


print "$file does not exist\n";


}

}

}

main();


else

{


print "$file does not exist\n";


}

}

}

main();

No comments:

Post a Comment