http://qs1969.pair.com?node_id=377110


in reply to how to merge the files of DNA sequences?

This is what I came up with:
#!/bin/perl5 use strict; use warnings; @ARGV = qw( file1.txt file2.txt ); my $name; my %hash; while (<>){ chomp; my $record = $_; if ( $record =~ /^>/ ){ $name = $record; next; } else{ $hash{$name} .= $record } } for my $key ( keys %hash ){ print "$key\n$hash{$key}\n" }
Updated: Use hash instead of a hashref

Replies are listed 'Best First'.
little golf
by ccn (Vicar) on Jul 24, 2004 at 10:34 UTC

    perl -lne '/^>(.*)/ or$H{$1}.=$_;END{print for map{">$_\n$H{$_}"}keys%H}' file1.txt file2.txt

      Ok, ok I'm impressed! I'm still at the 'baby idiom' stage.

      ...and anyway, I like typing!