My code below do3s not seem to be working. I want to read some files from a directory into an array and sort them by creation date:
#!/usr/contrib/bin/perl
use strict;
use warnings;
my $dir = "/OV_backup";
my @backups;
use vars qw($b $a);
opendir (DIR,$dir) or die ("Error opening $dir: $1"
;
my @files = readdir (DIR);
foreach (@files) {
next unless (/^OV_BACKUP.*/);
push (@backups,$_);
}
my @sort=sort {(-C $a) <=> (-C $b)} @backups;
print "@sort\n";
Here is what I am getting:
"Use of uninitialized value in numeric comparison (<=>)"
and the files are not printed out in creation order in my print statement.
Any help appriciated.
#!/usr/contrib/bin/perl
use strict;
use warnings;
my $dir = "/OV_backup";
my @backups;
use vars qw($b $a);
opendir (DIR,$dir) or die ("Error opening $dir: $1"
my @files = readdir (DIR);
foreach (@files) {
next unless (/^OV_BACKUP.*/);
push (@backups,$_);
}
my @sort=sort {(-C $a) <=> (-C $b)} @backups;
print "@sort\n";
Here is what I am getting:
"Use of uninitialized value in numeric comparison (<=>)"
and the files are not printed out in creation order in my print statement.
Any help appriciated.