Thanks for your help with my last post, it worked great. Now I am getting a little more complex and I need to make sure it works correctly or I may end up screwing up some of my data.

I have a folder tree of month names using the first 3 three letters (Jan, Feb, Mar). Inside each folder are text files, 1 for each day of the month. Titled 1.txt, 2.txt, 3.txt and so on and so on.

In my text file, I have the Month, Day, Year and Text. I want to automatically make a script go through my folder tree and input text where it should go (at the bottom of the correct Month/day file). A sample of the INPUT file is

Jan 1, 1915 (Birthday) Franck Pourcel - singer Jan 3, 1926 (Birthday) George Martin - singer Jan 3, 1945 (Birthday) Stephen Stills - singer Jan 3, 1946 (Birthday) John Paul Jones - singer
A sample of the file I am OUTPUTTING TO
1963 G Woods succeeds Eugene Black as president of the World Bank 1964 Federation of Rhodesia & Nyasaland dissolved 1965 International Cooperation Year begins
The output file only has the year, a space, and the TEXT. The other data from the INPUT file is used to locate the correct file.

This is what I have so far. I think it would work if the regex was matching, but it's not. Can anyone help me with this? I did the best I could.

#!/usr/bin/perl use warnings; use strict; open(LOG, "source.txt") or die "Error: $!"; my @lines = <LOG>; close(LOG); foreach my $line (@lines) { $line =~ m/(\w)\s+(\d+),\s+(\d+)\s+(\(Birthday\)\s.+)/i; # 1 is m +onth, 2 is day of month, 3 is year, 4 is the text print "$1 $2 $3 $4\n"; open(OUT, ">> $1/$2.txt") or die "Error"; # write our line appendi +ng to the bottom of the file print OUT "$3, $4\n"; } print "Done";

In reply to Simple line regex again 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.