"Michael S. Robeson II" <[EMAIL PROTECTED]> wrote in message ...
> open(DNA_SEQ, $dna_seq) Due to precedence, the parens are optional here. > open(OUTFILE, ">indel_list_"."$dna_seq") ^^^^^^^^^^^^^^^^^^^^^^^^^ ">indel_list_$dna_seq" or ">indel_list_".$dna_seq > foreach (keys %sequences) { > print "\t\t\>\>\>\>\>\> $_ \<\<\<\<\<\<\n"; > print OUTFILE "\>\>\>\>\>\> $_ \<\<\<\<\<\<\n"; The > and < do not need to be escaped. > $position{$gap_length} .= "$gap_pos"." \n"; "$gap_pos \n" or "$gap_pos\n" > foreach my $key (@keys) { > print "Indel size:\t$key\tTimes found:\t$gap_data{$key}\n"; > print OUTFILE "Indel size:\t$key\tTimes found:\t$gap_data{$key}\n"; > print "Positions:\n"; > print OUTFILE "Positions:\n"; > print "$position{$key}"; > print OUTFILE "$position{$key}"; > print "\n"; > print OUTFILE "\n"; > } As a general rule, whenever you keep doing the same thing in multiple places, think sub {}. See alternative below. ------------------ #!/usr/bin/perl use warnings; use strict; # By pre-declaring print2mfh, you can call it without parentheses! sub print2mfh; my($animal, %gap); # my $data = '/path/to/data.txt'; # open DATA, $data or die "Could not open $data: $!\n"; while (<DATA>) { />(\w+)/ and $animal=$1 and next; while ( /(-+)/g ) { push @{ $gap{$animal}{length $1} }, $-[1]+1; } } die "No gaps found!" unless scalar keys %gap; # if you are on unix or linux, use tee to print to multiple outputs # See Perl Cookbook 7.18 # open TEE, "| tee outfile.txt" or die "Could not tee off!: $!\n"; # instead of print2mfh and OUT, you would do: print TEE "text to print"; open OUT, ">output.txt" or die "Could not open output file: $!\n"; print "***Discovered the following DNA sequences:***\n"; print "$_ found!\n" for sort keys %gap; foreach my $animal(sort keys %gap) { print2mfh "\t\t>>>>>> $animal <<<<<<\n"; foreach my $length(sort {$a <=> $b} keys %{ $gap{$animal} }) { my $pos = [EMAIL PROTECTED] $gap{$animal}{$length} }; print2mfh "Indel size:\t$length\tTimes found:\t", scalar @$pos, "\n"; print2mfh join("\n", "Positions:", @$pos, "\n"); } } sub print2mfh { # print to multiple file handles foreach my $fh(*STDOUT, *OUT) { print $fh @_ } } __DATA__ >dog atcg--acgat---act-ca---- >cat acgt-acgt----acgt-gt-agct- >mouse ---acgtacg-atcg---actgac- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>