I run Perl on Windows and I get a list of all the files in the directory using readdir and storing the result in an array. The first two elements in the array always appear "." and "..". Is this order guaranteed (if the operating system does not change)?
I would like to do the following to remove these values:
my $directory = 'C:\\foo\\bar';
opendir my $directory_handle, $directory
or die "Could not open '$directory' for reading: $!\n";
my @files = readdir $directory_handle;
splice ( @files, 0, 2 );
But I am worried that this may be unsafe. All the solutions I've seen use regular expressions or instructions for each element in the array, and I would prefer not to use any of these approaches if I don't need it. Thoughts?
source
share