I am needing to create a new file from the following input file:

DB20121001@3575 1349124143.382
DB20120928@1234 1348865280.066
DB20120927@1234 1348778775.057
DB20120905@2341 1346877693.517
DB20120911@3575 1347396457.566
....


the output file for the first line should create a file (/3575/DB20121001) with the following txt.

<event> <stream-id>3575</stream-id> <event-name>DB20121001</event-name> <primary-event> <delete-time>Mon Oct 1 8:42:23 PM</delete-time> </primary-event> </event>

Here is what I am stuck:
#!/usr/bin/perl use DateTime; use IO::File; use POSIX qw(strftime); $LOGFILE = "second.txt"; open(LOGFILE) or die("Could not open log file."); foreach $line (<LOGFILE>) { chomp($line); # remove the newline from $line. ($stream, $timedate) = split("\t"); my $time_t = POSIX::strftime( "%Y-%m-%d %r", localtime($timedate) ); my ($streamid) = $stream =~ m!.*@([^_]*)-!; my ($streamname) = $stream =~ /(.*)?\@/; open (file, ">$streamid/$streamname") || die "file not opened"; print file "<event>\n"; print file "<stream-id>$streamid</stream-id>\n"; print file "<event-name>$streamname</event-name>\n"; print file "<primary-event>\n"; print file "<delete-time>$time_t</delete-time>\n"; print file "</primary-event>\n"; print file "</event>\n"; close (file); } close (LOGFILE);
I am stuck why this is not looping through and creating these files.
I have been successful in creating a single file with _all_ the output, but I need to get a file per line.
thanks.

In reply to new file per line output by monteryjack

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.