Hello guys. Can someone explain to me how would one come up with the idea behind the code from line 12 to 18? I mean I kind of understand it but I would have never though of it :-). (It's from Intermediate Perl book, by the way).

1 #!perl 2 use strict; 3 use warnings; 4 use utf8; 5 use File::Find; 6 use Time::Local; 7 my $target_dow = 1; # Sunday is 0, Monday is 1, ... 8 my @starting_directories = ("."); 9 my $seconds_per_day = 24 * 60 * 60; 10 my($sec, $min, $hour, $day, $mon, $yr, $dow) = localtime; 11 my $start = timelocal(0, 0, 0, $day, $mon, $yr); # midn +ight today 12 while ($dow != $target_dow) { 13 # Back up one day 14 $start -= $seconds_per_day; # hope no DST! :-) 15 if (--$dow < 0) { 16 $dow += 7; 17 } 18 } 19 my $stop = $start + $seconds_per_day; 20 my($gather, $yield) = gather_mtime_between($start, $stop); 21 find($gather, @starting_directories); 22 my @files = $yield->( ); 23 for my $file (@files) { 24 my $mtime = (stat $file)[9]; # mtime via slice 25 my $when = localtime $mtime; 26 print "$when: $file\n"; 27 }
I have never taken any courses in computer science or software engineering. -- esr (http://www.catb.org/~esr/resume.html)

In reply to Day of week calculation by reisinge

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.