perhaps you could work with something from the command line like

for i in `find . *.txt`; do perl -pi -e 's/\n/,/' $i; done;

update or maybe a Perl only solution. This one uses recursion to traverse subdirs.

#!/usr/bin/perl use strict; use warnings; my $dir = "."; lista_dirs($dir, $dir); sub lista_dirs { my ($dir, $dirname) = @_; my (@dirs, @files); opendir DIR, "$dir"; my @dircontent = grep { /[^\.]/ } readdir(DIR); closedir DIR; @dirs = (); @files = (); foreach(@dircontent) { if(-d "$dir/".$_) { push @dirs, $_; } else { push @files, $_ if($_ =~ /\.txt$/); } } foreach my $d(@dirs) { lista_dirs("$dir/".$d, $d); } # IMPORTANT NOTE: if your files aren't too big, you can read every +thing at once as shown in the code below. # if note, you can open +the input file for reading and a temp file for wirting. Read the file + line by line, # replace \n with the , and write to the temp file +. Close both files when you're done, and then 'rename' # the temp file to the input filename foreach my $file (@files) { $/ = ''; open FILE, "$dir/$file"; my $content = <FILE>; close FILE; $content =~ tr/\n/,/; open FILE, ">$dir/$file"; print FILE $content; close FILE; } return; } <p><b>update 2</b> After reading the other replies I realized I misrea +d the question, and there was no need for recursion, so the solution +came to be more complex than it needed to be. I was really in the nee +d to get some sleep.</p>

In reply to Re: parsing files and modifying format by olus
in thread 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.