Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Space inserted into output file

by poj (Abbot)
on Jul 22, 2017 at 16:29 UTC ( [id://1195786]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1195786]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-19 09:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found