Hi all, I have a directory with gzip'd files with the following format:
1999-04-22_weather.log.gz 1999-04-24_weather.log.gz 1999-04-25_weather.log.gz 1999-04-27_weather.log.gz You get the idea. Now suppose I want to see if files for a particular date range are available: my attempt at code is: ($nyear,$sdate,$edate) = @ARGV; ($sday,$smon) = split('-',$sdate); ($eday,$emon) = split('-',$edate); $sdate_cursor = [$nyear,$smon,$sday-1]; $edate_cursor = [$nyear,$emon,$eday]; @list = `ls -1 *_weather.*`; foreach $file (@list) { chomp($file); ($date,$dummy) = split(/\_/,$file); ($year,$month,$day) = split('-',$date); last if (compare_dates([$year,$month,$day], $edate_cursor) > 0); if (compare_dates([$year,$month,$day], $sdate_cursor) > 0 ) { push (@array, $file) if -e $file; } } sub compare_dates { my($a, $b) = @_; foreach (0..2) { if ($$a[$_]>$$b[$_]) { return 1; } elsif ($$a[$_]<$$b[$_]) { return -1; } } return 0; } As you can see from the list of files above, the files for the 23rd and 26th of April is missing. What could I do to get the script to report that these files are not present????? Thanks in advance. Stacy

In reply to Does a file really exist? by maderman

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.