You have a number of things missing.  The group will tell you to use
warnings and strict. This would have highlighted a number of items.

        Here is the snippet of code using __DATA__ for the data:

my @test_number = ();
my $i= 0;
my %hast_try = ();

while(<DATA>) {
        if ( /test_number/i ) {
           @test_number=split(/\<|>/,$_);
           $hash_try{$i}=$test_number[2];
         $i++;
         } 
 }
# close(XML);

foreach my $MyKey (sort keys %hash_try){
print"$MyKey=>$hash_try{$MyKey} \n";}

Output:
0=>1
1=>2

        A start for you.

Wags ;)

-----Original Message-----
From: Sugrue, Sean [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, September 25, 2002 10:06
To: [EMAIL PROTECTED]
Cc: Sugrue, Sean
Subject: hash



I am trying to create a hash that takes an xml input from a file retrieves
all
lines
that has the word test_number in it, splits it to retrieve the actual test
number and then
when the hash is populated "while" through it and print out the keys and
values.
I don't really have a good grasp of how to create, populate and manipulate
hashes so 
I'm running into problems. Anyone have a suggestion?
Below is a sample of my code not yet finished and some 
of the text from the xml file.

#!/usr/local/bin/perl
$i=0;

print" trying open a file \n";
open(XML, "temp.xml") || die("Cannot open file \n");
while(<XML>)
{
        if($_=~/test_number/){
                @test_number=split/\<|>/,$_;
                $hash_try{$i}=$test_number[2];
                $i++;
                } 
}
close(XML);

while(($key,$value)=(%test)){
print"$key=>$value \n";}


XML file sample


<begin_program_seg>
<section_name>CONTINUITY_seq</section_name>
</begin_program_seg>

<functional_result>
<test_number>1</test_number>
<head_num>1</head_num>
<site_num>0</site_num>
<test_flags alarm='n' reliable_test='y' timeout='n' executed='y' aborted='n'
passed='y' ></test_flags>
<description><![CDATA[
+ dig opn/sht <> CONTINUITY_test
]]></description>
<patt_gen_num>0</patt_gen_num>
</functional_result>

<functional_result>
<test_number>2</test_number>
<head_num>1</head_num>
<site_num>0</site_num>
<test_flags alarm='n' reliable_test='y' timeout='n' executed='y' aborted='n'
passed='y' ></test_flags>
<description><![CDATA[
- dig opn/sht <> CONTINUITY_test
]]></description>
<patt_gen_num>0</patt_gen_num>
</functional_result>



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


**********************************************************
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
****************************************************************


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to