slinky66 has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

I am experiencing some weirdness inside my if/elsif/else block. The "if" condition is returning false and falling through even though the file being checked in the "if" condition does exist. Any ideas?

use strict; my $line; if ( -e "/usr/www/htdocs/images/items/350/$itemid.jpg") { $line .= "http://www.store.com/images/items/350/$itemid.jp +g"; } elsif ( -e "/usr/www/htdocs/images/items/215/$itemid.jpg" ){ $line .= "http://www.store.com/images/items/215/$itemid.jp +g"; } else { $line .=""; }

Replies are listed 'Best First'.
Re: -e falling through
by Anonymous Monk on Dec 08, 2009 at 16:38 UTC
    Try
    -e $file or die "what happened? $! $^E";
      Great. Thanks. That helped me figure out what was going on

      It's only an error if -e returned undef.

      defined(my $exists = -e $file) or die("Error checking if \"$file\" exists: $! $^E\n"); print("$file ", ($exists ? "exists" : "doesn't exist"), "\n");