I want to list the files in the folder and want to store in array. How can I make the array can be access outside the loop? I need that array to be outside as need to use it outside the array
This is the code:
use strict;
use warnings;
my $dirname = "../../../experiment/";
my $filelist;
my @file;
open ( OUTFILE, ">file1.txt" );
opendir ( DIR, $dirname ) || die "Error in opening dir $dirname\n";
while ( $filelist = readdir (DIR) ) {
next if ( $filelist =~ m/\.svh$/ );
next if ( $filelist =~ m/\.sv$/ );
next if ( $filelist =~ m/\.list$/ );
push @fileInDir, $_;
}
closedir(DIR);
print OUTFILE " ", @fileInDir;
close OUTFILE;
The error message is
Use of uninitialized value in print at file.pl line 49.