I am having a problem checking the existance of a file. I have ran the code used to check for the file in a seperate test file and it works fine. For some reason when present in this script it doesn't execute the needed code, which makes me assume that the -e if returning 0. In my test file I simulated the code as exactly as possible with regards to nested ifs with a foreach and the method in which the filename is described (${save_dir}${filename}). Anyone see what I'm missing?

#!/usr/bin/perl -w use strict; use HTML::SimpleLinkExtor; use LWP::Simple; use Image::Grab; my $save_dir = ">/home/dir/"; my $page = 'http://website.com/webpage.html'; my $link; my $image; my $counter = 0; my $pic = Image::Grab->new(); my $html = get($page); my $extor = HTML::SimpleLinkExtor->new(); $extor->parse($html); my @page_links = $extor->links; my @temp = split(/\//, $page); pop(@temp); my $page_dir = join('/', @temp) . "/"; @temp =""; print "$page_dir\n"; foreach $link (@page_links) { if ($link =~ /jpg$/) { next if $link =~ /small.jpg$/; print $link . "\n"; $counter++; my @temp = split(/\//, $link); my $filename = pop(@temp); #Here is the suspect code if (-e "${save_dir}${filename}") { print "$filename exists, skipping file"; next; } print "Save Dir = ${save_dir}${filename}\n"; print "Image URL = ${page_dir}${link}\n"; $pic->url($page_dir . $link); $pic->grab; open(IMAGE, "${save_dir}${filename}") || die "$!"; print IMAGE $pic->image; close IMAGE; print "${counter}: Saved $link \n\n"; } } print "Finished!\n";

----
Nothing in the world can take the place of persistence. Talent will not; nothing is more common than unsuccessful men with talent. Genius will not; unrewarded genius is almost a proverb. Education will not; the world is full of educated failures. Persistence and determination alone are omnipotent. --Calvin Coolidge (1872-1933)

In reply to Failed file existance check by PerlJam

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.