Isto:
use XML::Twig;
my $file = $ARGV[0];
$file =~ /(.+)\.xml/;
my $outfile = $1.".snp" ;
open my $out,'>',$outfile or die "Could not open file '$outfile' $!";
my $twig = XML::Twig->new
(
twig_handlers =>
{
'Rs/MergeHistory' => \&MergeHistory,
}
);
# Here starts changed code.
my %output = ( "rs", (),
"b" , () );
$twig -> parsefile( "$file" );
my $inLine = 2; # You said You want 2 in one line.
while( @{$output{"rs"}} ) {
for( my $i=0; $i < $inLine; $i++ ) {
print "rs" . ( shift @{$output{"rs"}} ) . ",";
}
print "\t";
for( my $i=0; $i < $inLine; $i++ ) {
print "b" . ( shift @{$output{"b"}} ) . ( $i == $inLine-1 ? "" : "," );
}
}
print "\n";
sub MergeHistory
{
my ($twig, $elt) = @_;
push @{$output{"rs"}}, ( "rs" . $elt->att('rsId') );
push @{$output{"b"}}, ( "b" . $elt->att('buildId') );
}
imprimirá isso:
rs56546490,rs386588736, b130,b142