in reply to Reading Multiple lines

Perhaps you want something like this:

@ARGV == 2 or die "usage: $0 input_file output_file\n"; open OUTFILE, '>', "$ARGV[1]temp.csv" or die "Cannot open '$ARGV[1]tem +p.csv' $!"; open INFILE, '<', $ARGV[0] or die "Cannot open '$ARGV[0]' $!"; while ( <INFILE> ) { chomp; $\ = /"$/ ? "\n" : ' '; print OUTFILE $_; } close INFILE; close OUTFILE;

Replies are listed 'Best First'.
Re^2: Reading Multiple lines
by mick2020 (Novice) on Oct 15, 2008 at 11:44 UTC
    Hi,
    I have tried your suggestion and it does not solve the problem
    I have compared the format of the output of this with the
    format of a file that has no carriage return and the
    formats are identical
    use FileCache maxOpen => 50; # config: my $field = 0; my $sep = ","; $, = $sep; $\ = $/; my %file; my $fnum = 1; my $outDir = $ARGV[1]; unless (-d $outDir){ die "There is a no such directory."; } open PROCESSEDFILE, $ARGV[0] or die $!; while (<PROCESSEDFILE>) { chomp; my @c = split(/$sep/,$_); my( $key, $num ) = defined $c[$field] ? ( $c[$field], $fnum++ ) : ( '(column not present)', 0 ); unless ( $file{$key}) { $nameF = $c[$field]; $nameF =~ s/"//g; $file{$key}{num} = $num; $file{$key}{name} = $ARGV[1].$nameF.$end; if(($file{$key}{num}) >1){ -f $file{$key}{name} and die "Sorry, '$file{$key}{name}' exists; won't clobber."; $file{$key}{fh} = cacheout $file{$key}{name} or die "Error opening '$file{$key}{name}' for write - $!"; }} print {$file{$key}{name}} @c; }
    This is the code for the next part of the processing.
    The output of this is okay for files that are not preprocessed.
    When I use a preprocessed file as input to this. It will
    process the records that had the carriage return ok but it doesn't process records that where formatted properly in
    the original file
    I am thinking that there is some character that I am inserting
    when processing the records that have \r\n and leaving it out
    when writing the records that don't have these
    but I can't spot it.