Hi All Monks,

I am pretty new to perl and I wrote a small perl script to ease my pain, did not work.

My input looks like this with over 20 line in the text file.

18:06:04.616 [79952.57692] <2> logparams: -S server1.prod.com -D serve +r2.prod.com -C server3.prod.com -X -s 1421467204 -e 1421467204 -R E:\ +Program Files\725635\logs\log.tmp.chg -K -t 13 -M -k -L E:\Program F +iles\725635\logs\infod.tmp.log -W -f E:\Program Files\725635\logs\aft +er.tmp 17:49:34.216 [58140.81564] <2> logparams: -S -l -a -k server1.prod.com + -D client10.prod.com -C sql12.prod.com -X -s 1421467205 -e 142146720 +5 -R E:\Program Files\561234\logs\log.tmp.chg -K -t 13 -M -k -L E:\P +rogram Files\561234\infod10.tmp.log -W -f E:\Program Files\561234\log +s\after.tmp

and my output should look like this:

server1.prod.com,server2.prod.com,server3.prod.com,725635,infod.tmp.lo +g server1.prod.com,client10.prod.com,sql12.prod.com,561234,infod10.tmp.l +og

My script look like this, it worked only when the count is right as you can see the second line the count went way off, the fields count in my code is not accurate but you get the point. I need a different logic, can you guys help me out.. Thank you all

open(FILE, $filename) or die "Could not read from $filename, program h +alting."; while(<FILE>) { # get rid of the pesky newline character chomp; # read the fields in the current record into an array @fields = split(/[\s\\]+/, $_); $datestring = localtime(); open logreport, ">>E:\\temp\\logs\\eligiblereport.txt"; print logreport "$date,$fields[5],$fields[7],$fields[9],$fields[24] +,$fields[43]\n"; } close logreport; close FILE;

In reply to help with splitting and printing the array by perlnewbie012215

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.