Vineet Pande wrote:
> hi,

Hello,

> In the following code which reads a file.txt (SEE ATTACHMENT) where I am
> trying to understand how to put the DNA sequence in to a single string...
> 
> print "enter file with DNA sequence: ";
> $seqfile = <STDIN>;
> chomp $seqfile;
> unless ( open(DNAFILE, $seqfile) )
> {
> print "can't open!!\n";
> exit;
> }
> @dna = <DNAFILE>;
> close DNAFILE;
> 
> $dna = join( '', @dna);
> print "$dna\n";
> 
> THE OUTPUT IS EXACTLY THE SAME AS IN file.txt.....Why don't we get the
> string joined...of course i agree i must clean whitespace...bu then what
> is expected out of join( '', ....). WHAT '' means?

'' is just a(n empty) string.

$x = join '', 'string1', 'string2', 'string3';

Is the same as:

$x = 'string1' . '' . 'string2' . '' . 'string3';

Which is the same as:

$x = 'string1' . 'string2' . 'string3';


In your case you can concatenate directly to $dna without using an array:

my $dna;
while ( <DNAFILE> ) {
    $dna .= $_;
    }
print "$dna\n";


Or the usual perl way to do it (by undefining the input record separator):

my $dna = do { local $/; <DNAFILE> };
print "$dna\n";




John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to