in reply to Space inserted into output file

see perlvar

$LIST_SEPARATOR
$"
When an array or an array slice is interpolated into a double-quoted string or a similar context such as /.../ , its elements are separated by this value. Default is a space. For example, this:
    print "The array is: @array\n";
is equivalent to this:
    print "The array is: " . join($", @array) . "\n";

Either use
{ local $" = ''; print FH "@fasta"; }

or

print FH join '',@fasta;

or just print out each line as it is read

#!/usr/local/bin/perl use strict; use Text::CSV; use Data::Dumper qw(Dumper); print "Enter input file name : "; my $file = <STDIN>; chomp $file; open my $in, '<', $file or die "Could not open '$file' $!\n"; print "Enter output file name: "; my $ofile = <STDIN>; chomp $ofile; open my $out, '>', $ofile or die "Could not open '$ofile' $!\n"; my $csv = Text::CSV->new({ sep_char => ',' }); my $count = 0; while (my $line = <$in>) { if ($csv->parse($line)) { my @fields = $csv->fields(); $fields[4]=~s/\s//g; #removes spaces within the sequence print $out '>'.(join '_',@fields[0..3])."\n$fields[4]\n"; } else { warn "Line could not be parsed: $line\n"; } ++$count; } close $in; close $out; print "$count lines read from $file to $ofile\n";
poj

Replies are listed 'Best First'.
Re^2: Space inserted into output file
by He77e (Initiate) on Jul 23, 2017 at 17:44 UTC

    Cheers mate, works perfectly!

    Rob

    2017-07-25 Athanasius restored original content