Hi Monks!
I got this Perl code from here as an example, could someone explain to me if this is right, because it seems to be wrong, (this is how Delta Days should be "Delta_Days(2002, 06, 20, 2001, 06, 20), I dont know how to used it with the ">30", but I just would like someone to explain to me what is happening there.
(Delta_Days($3, $months{$1}, $2, $today[2], $today[1], $today[0]) > 30 + )? push @log_lines, $line : keep_line($line);

Here is where this line come from and inside the while loop, once it is running it goes or runs forever
Thanks!
#!/usr/bin/perl -w use Date::Calc qw(Delta_Days); my $dirname = "."; my (@files, @log_lines); my %months = ( 'Jan' => 1, 'Feb' => 2, 'Mar' => 3, 'Apr' => 4, 'May' => 5, 'Jun' => 6, 'Jul' => 7, 'Aug' => 8, 'Sep' => 9, 'Oct' => 10, 'Nov' => 11, 'Dec' => 12, ); # get the list of text files opendir DIR, "$dirname"; @dircontent = grep { /\.txt$/ } readdir(DIR); closedir DIR; # Compute today's date my @today = (localtime(time))[3..5]; $today[1]++; $today[2] += 1900; # foreach text file, compute lines condition foreach $filename (@dircontent) { open FILE, "<$filename"; while(<FILE>) { my $line = $_; # see if line matches date format if($line =~ /^\[(\w{3}?) (\d{2}?)[^\]]*(\d{4}?)(.*)$/) { # assumed 'one month older' as being over 30 days. # if the line is older than 30 days, save it into an array # and write it later. If not, write it to a temp file (Delta_Days($3, $months{$1}, $2, $today[2], $today[1], $today[0] +) > 30 )? push @log_lines, $line : keep_line($line); } else { keep_line($line); } } close FILE; # The following lines restore the initial file but without old lines unlink $filename; rename "temp.tmp", $filename; } # archive old lines open ARCH, ">>archive.arc"; foreach $line (@log_lines) { print ARCH "$line"; } close ARCH; # Just append a line to temp file sub keep_line { my $line = shift; open TEMP, ">>temp.tmp"; print TEMP "$line"; close TEMP; }


Thanks again!

Considered by g0n: "This seems to be continuation of Comparing Dates as noted by mikeraz. Reparent in the original thread?"
Unconsidered by jdporter (3/4/0)


In reply to Date::Calc Question by Anonymous Monk

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.