You've lost me.

I assume that in the code in 717191 the PROCESSEDFILE is the file produced by stitching the CSV stuff together. I pushed the bits of code together, as best as I can, to get it to run. The $end variable was undefined and the $nameF variable was missing its my -- but apart from that it runs.

First time through the while (<PROCESSEDFILE>) loop: $num will be set to 1, so if ($file{$key}{num} > 1) will fail, so no file will be opened. I cannot figure out what this is trying to do, but I suspect it's trying not to open a file in the '(column not present)' case -- and making a mess of it.

Incidentally, the first time it gets a '(column not present)' case it will pass the unless ($file{$key}) test and promptly set my $nameF = $c[$field], although $c[$field] is already known to be undefined. Not sure I see the point of that, either.

Finally, under all conditions -- including '(column not present)' and when it has failed to open a file -- it gets to the print {$file{$key}{name}} @c; line. What is this intended to do ? Under strict it gives me

  Can't use string ("/somewhere/data.END") as a symbol ref while "strict refs" in use ...
but for all I know it does something wonderful in non-strict. I note however that you set $file{$key}{fh} which looks like a dead ringer for somewhere to output to ?

Between you and me this looks like a bit of a train wreck. I suggest putting in the odd print statement here and there so that you can tell what's going on at each stage in the process... that may show you where things are and are not working as you expect.

BTW: I recommend Markup in the Monastery

use strict ; use warnings ; my $PROCESSEDFILE = '' ; open PROCESSEDFILE, '>', \$PROCESSEDFILE ; while (<DATA>) { while (($_ !~ /"\s*$/) && !eof) { s/[\r\n]+$// ; $_ .= ' '.<DATA> ; } ; print PROCESSEDFILE $_; } close PROCESSEDFILE ; open PROCESSEDFILE, '<', \$PROCESSEDFILE ; #use FileCache maxOpen => 50; # config: my $field = 0; my $sep = ","; my $end = '.END' ; $, = $sep; $\ = $/; my %file; my $fnum = 1; my $outDir = '/somewhere/' ; #$ARGV[1]; #unless (-d $outDir) { die "There is a no such directory." ; } #open PROCESSEDFILE, $ARGV[0] or die $!; while (<PROCESSEDFILE>) { chomp; print "processing '$_'\n" ; my @c = split(/$sep/, $_); my( $key, $num ) = defined $c[$field] ? ( $c[$field], $fnum++ ) : ( '(column not present)', +0 ) ; unless ($file{$key}) { my $nameF = $c[$field]; $nameF =~ s/"//g; $file{$key}{num} = $num; $file{$key}{name} = $ARGV[1].$nameF.$end; if ($file{$key}{num} > 1) { print "opening $file{$key}{name}" ; # -f $file{$key}{name} # and die "Sorry, '$file{$key}{name}' exists; won't clobber +."; ($file{$key}{fh} = 1) #cacheout $file{$key}{name} or die "Error opening '$file{$key}{name}' for write - $!"; } } print {$file{$key}{name}} @c; } __DATA__ "data", "data" ,"data", "data","data", "data" "data", "data" ,"data", "data with new line ", "and some more! ","data", "data" "data", "data" ,"data", "data","data", "data" "tada", "tada

In reply to Re^3: Reading Multiple lines by gone2015
in thread Reading Multiple lines by mick2020

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.