>>> "Vineet Pande" <[EMAIL PROTECTED]> 08/08/2005 9:39:00 am >>>

>@dna = <DNAFILE>;
[snip]
>$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?

You do get the string joined. The string contains the newlines from the
file, that will cause the printed string to look just like the file.

Each element of @dna contains one line of the file.  The join with
empty quotes basically mashes all the elements of @dna together into one
string without any extra connecting characters.  Like so:

my @example = ("This is one line\n", "This is another");
my $string = join '', @example;
print $string;

The output will look like this:

This is one line
This is another

So, you've got a couple of options here.  One thing to do would be to
"chomp @dna" to get rid of the trailing newlines in each element.  The
other thing you could do would be to get rid of the array @dna
altogether:

# The "or die" is the preferred way of checking open success, by the
way
# Also, note the use of "$!" to determine failure cause
open DNAFILE, $file or die "Cannot open file: $!";
my $dna = join '', <DNAFILE>;
close DNAFILE;
# Now we get rid of any newlines
$dna =~ s/\n//g;

This way you don't have two copies of the file in memory.

Hope this helps,

Jeff Eggen
IT Programmer Analyst
Saskatchewan Government Insurance
************DISCLAIMER*************
This e-mail and any files transmitted with it are confidential and intended 
solely for the use of the individual or entity to whom they are addressed.  If 
you are not the named addressee, please notify the sender immediately by e-mail 
if you have received this e-mail by mistake and delete this e-mail from your 
system. If you are not the intended recipient you are notified that using, 
disclosing, copying or distributing the contents of this information is 
strictly prohibited.
************DISCLAIMER*************

-- 
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