Hello all,
I do have script that open files with filename matching this pattern: *Dec2003*.txt and processes them. Unfortunatelly, some of the files belongs to different month, (January) even though their name says *Dec2003*.txt. So for example this file:
-rw-r--r-- 1 user group 642 Dec 29 23:00 TA29Dec2003-0.zip.LOG.summary.txt
should be processed as December 2003, however, this file:
-rw-r--r-- 1 user group 628 Jan 1 01:14 TA31Dec2003-1.zip.LOG.summary.txt
should be processed as January 2004!
Here is the script:
#!usr/bin/perl -w use strict; use Fcntl qw[:flock]; my $impressions = 0; my$iofile = '/other/scripts/daniel/input/c07_impressions_io.info'; open (IO, $iofile) || die("Could not open file 1!"); while (<IO> ) { chop; (my$FH, my$output, my$file2check) = split (/\s+/, $_); open OUT, ">> $output"; chdir $FH or die "$!"; while (glob $file2check) { open FH, $_ or die $!; flock FH, LOCK_SH or die $!; while (<FH> ) { chomp; if ( /Impressions:/ ) { my($text, $value) = split(/:/, $_); $impressions += $value if ($value =~ /\d+/); } } close FH or die $!; } } print OUT 'Total impressions: ', $impressions or die $!;
the my$iofile contains: 1. where the files I am interested are, 2. where to write the total, 3. and then the pattern (*Dec2003*.txt)
Please advice.
Thank you for your time.

In reply to How to process only files created on specific month? by danield

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.