in reply to Print Output to New File
Hi, as was pointed out in a fashion by another monk, you have a great deal of duplication in your code. One of the great things about variables is that they are, um, variable. That is, they can hold variable values. Thus, you don't need a different variable for each piece of data you are processing. Then, once you are reusing variables, you will find that you can reuse code that processes them.
Another important technique is to use meaningful variable names, so that a reader of code, or you a week later, can understand what is going on.
So for example I might gently rewrite your code to contain something like:
(example code only)... my @infiles = @ARGV; for my $file ( @infiles ) { my ($descriptions, $sequences) = ParseFile( $file ); ... # output the data here } ... sub ParseFile { my $file = shift; my %descriptions = my %sequences = (); open (my $fh, '<', $file) or die "Cannot open input file $file: +$!\n"; while ( my $line = <$fh> ) { chomp $line; if ( $line =~ m/^>(\S+)\s(.+)/ ) { $descriptions{$1} = $2; } else { $sequences{$1} = $.; } } return (\%descriptions, \%sequences); } ...
Hope this helps!
|
|---|