jeudi 6 septembre 2018

If statement not seeing seeing file in perl

Im new to perl and I am having an issue with the if statement in perl. I am not able to get the if statement where it sees the file. I basically have files with extension .new and .old.

my $dir = "/Users/henry/Desktop/perltest/templates";
my @oldfiles = glob "$dir/*.new";
my $oldfile;

print "checking for new templates\n";
foreach $oldfile (@oldfiles){
    print "$oldfile\n";

    if($oldfile =~ /(\S+)\.new/) {
      my $newfile = $1;
      print "$newfile\n";
      if (-e $newfile) {
        print "file exist\n";
      }else {
        print "file does not exist\n";
      }
    }
};

Here is my output:

checking for new templates /Users/henry/Desktop/perltest/templates/a.txt.new /Users/henry/Desktop/perltest/templates/a.txt file does not exist /Users/henry/Desktop/perltest/templates/b.txt.new /Users/henry/Desktop/perltest/templates/b.txt file does not exist /Users/henry/Desktop/perltest/templates/m.txt.new /Users/henry/Desktop/perltest/templates/m.txt file does not exist /Users/henry/Desktop/perltest/templates/n.txt.new /Users/henry/Desktop/perltest/templates/n.txt file does not exist

Aucun commentaire:

Enregistrer un commentaire