in reply to Re: Print multiple value from file
in thread Print multiple value from file

Oh sorry I made syntax error, I updated the script, but even when I search for subSnpClass, it print ssId twice

Replies are listed 'Best First'.
Re^3: Print multiple value from file
by poj (Abbot) on Aug 10, 2015 at 10:50 UTC
    After corrections to these 2 lines
    # $_= ~ /ssId=\s*?(\S+)/ $_ =~ /ssId=\s*?(\S+)/ #if ($_= ~ /subSnpClass=\s*?(\S+)/) if ($_ =~ /subSnpClass=\s*?(\S+)/)

    I got this result

    RS_SNPs subSnpClass3931 snp 76536062 snp
    maybe try this
    #!perl use strict; use warnings; my $Gene = 'ds_chY.xml'; my $outfile = 'ID.txt'; open my $out,'>',$outfile or die "Could not open file '$outfile' $!"; print $out "RS_SNPs\tsubSnpClass\n"; open my $in,'<',$Gene or die "Could not open file '$Gene' $!"; while (<$in>){ if ( /ssId=\s*"([^"]+)/ ){ print $out "$1\t"; } if ( /subSnpClass=\s*"([^"]+)/ ){ print $out "$1\n"; } }
    poj

      Oh, thanks a lot, it works now, but when I tried to print observed data such C/T, it does not work. and very thanks for your help

        Consider using XML::Twig for parsing XML

        #!perl use strict; use warnings; use XML::Twig; my $twig = new XML::Twig( twig_handlers =>{ 'Ss' => \&Ss } ); $twig->parsefile('ds_chY.xml'); sub Ss { my ($t,$e) = @_; my $obs = $e->first_child('Sequence')->first_child('Observed'); print $e->att('ssId')."\t".$e->att('subSnpClass')."\t"; print $obs->text."\n"; }
        UPDATE : added Observed

        poj