I am trying to parse a directory of files which are comma delimited each field value pair contains a , and a newline seperator is at the end of the field value pair, I would like to readin the entire directory of files and modify the file itself to be a csv file without the new lines I would like to replace the newlines with comma's basically this should be fairly easy to do, but I am having trouble figuring out how to do it. all I really need is to change the file so that I have label,value, so I can import it into excel. here is what I have so far.. oh and the stuff in the bottom is a an example of the source files format..
#!/usr/local/bin/perl use File::Find; $dirname=argv[]; my ($maxwidth)=0; my (%cmTime,%hMtime,%oMtime); my ($file,$base,$fmt); opendir(DIR, $dirname) or die "can't opendir $dirname: $!"; while (defined($file = readdir(DIR))) { next unless ($base)=$file=~/(.+)\.txt$/; open (fh, ">", $file) or die "Can't openfile $file: $!"; while (<fh>) { chomp; ($timestamp,@fields)=split/,/; } close (fh) or die "unable to close $file: $!"; $actioncode=$timestamp; if ($actioncode='Login') { print "found login"; } print ("succesfully opened file"); print("$file \n"); } closedir(DIR);
/8/2008 1:37:12 AM Login,27.742460 SearchLoad,21.855703 SearchCount,45:43.520663 SearchResults,69.364964 SearchSave,107.611750 SearchDelete,29.317471 SearchDetails,10.493312 TaxLoad,24.488549 TaxResults,197:15.273238 TaxDetails,10.222830 ClientAdd,10.763459 CMALoad,7.398715 CMASave,16.196349 CMADelete,3.009030 ClientDelete,6.442495 Logout,0.873738

In reply to parsing files and modifying format by grashoper

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.