Hi all, I am new user in perl, I want to extract two values from XML file and save them in new file. The values are ssId and subSnpClass. I create the following code, but it just print ssId twice and does not print subSnpClass. Any idea about how to fix it. Thanks

my $Gene='ds_chY.xml'; my $filename = 'ID.txt'; my $ID; my $subSnpClass; open(my $fh, '>', $filename) or die "Could not open file '$filename' $ +!"; print $fh "RS_SNPs\tsubSnpClass"; open(GTFFILE, $Gene) or die ("Cannot open the file"); while(<GTFFILE>){ $_=~ s/^\s+//; if ($_= ~/ssId=\s*?(\S+)/) { $ID=$1; $ID =~ s/"//; chop $ID; print $fh "$ID\n"; } if ($_= ~/subSnpClass=\s*?(\S+)/) { $subSnpClass=$1; $subSnpClass =~ s/"//; chop $subSnpClass; print $fh "\t$subSnpClass\n"; } }

Here is sample of my input file

===========================================================

<?xml version="1.0" encoding="UTF-8"?> <ExchangeSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xml +ns="http://www.ncbi.nlm.nih.gov/SNP/docsum" xsi:schemaLocation="http: +//www.ncbi.nlm.nih.gov/SNP/docsum ftp://ftp.ncbi.nlm.nih.go v/snp/specs/docsum_3.4.xsd" specVersion="3.4" dbSnpBuild="144" generat +ed="2015-05-26 09:54"> <SourceDatabase taxId="9606" organism="human" gpipeOrgAbbr="hs"/> <Rs rsId="3894" snpClass="snp" snpType="notwithdrawn" molType="gen +omic" genotype="true" bitField="050028000005130500030100" taxId="9606 +"> <Het type="est" value="0.05" stdError="0.1547"/> <Validation byCluster="true" byOtherPop="true" byHapMap="true" + by1000G="true"> <otherPopBatchId>7179</otherPopBatchId> </Validation> <Create build="36" date="2000-09-19 17:02"/> <Update build="144" date="2015-05-07 10:52"/> <Sequence exemplarSs="491581208" ancestralAllele="C,C"> <Seq5>ATAAGCAAATAACTGAAGTTTAATCAGTCTCCTCCCAGCAAGTGATATGCAA +CTGAGATTCCTTATGACACATCTGAACACTAGTGGATTTGCTTTGTAGTAGGAACAAGGTACATTCGCG +GGATAAATGTGGCCAAGTTTTATCTGCTGCCAGGGCTTTCAAATAGGTTGACCTGACAA TGGGTCACCTCTGGGACTGA</Seq5> <Observed>C/T</Observed> <Seq3>AATTAGGAAGAGCTGGTACCTAAAATGAAAGATGCCCTTAAATTTCAGATTC +ACAATTTTTTTTTCTTAGTATAAGCATGTCCCATGTAATATCTGGGATATACTCATACCTTTAAAAATG +TGCTCATTGTTTATCTGAAATTCACATTTTAACAGGGAACCATTGTTTTGTTATTGTTT ATTGTTTTGTTTCTAAATAA</Seq3> </Sequence> <Ss ssId="3931" handle="OEFNER" batchId="489" locSnpId="M3" su +bSnpClass="snp" orient="forward" strand="bottom" molType="genomic" bu +ildId="36" methodClass="DHPLC" validated="by-cluster"> <Sequence> <Seq5>TAATCAGTCTCCTCCCAGCAAGTGATATGCAACTGAGATTCCTTATGA +CACATCTGAACACTAGTGGATTTGCTTTGTAGTAGGAACAAGGTACATTCGCGGGATAAATGTGGCCAA +GTTTTATCTGCTGCCAGGGCTTTCAAATAGGTTGACCTGACAATGGGTCACCTCTGGGA CTGA</Seq5> <Observed>C/T</Observed> <Seq3>AATTAGGAAGAGCTGGTACCTAAAATGAAAGATGCCCTTAAATTTCAG +ATTCACAATTTT</Seq3> </Sequence> </Ss> <Ss ssId="76536062" handle="AFFY" batchId="52074" locSnpId="AF +FY_6_1M_SNP_A-8397107" subSnpClass="snp" orient="forward" strand="bot +tom" molType="genomic" buildId="130" methodClass="hybridize " validated="by-submitter"> <Sequence> <Seq5>TCACCTCTGGGACTGA</Seq5> <Observed>C/T</Observed> <Seq3>AATTAGGAAGAGCTGG</Seq3> </Sequence> </Ss>

In reply to Print multiple value from file by Helan_Ahmed

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.