perl script to create hash.


 
Thread Tools Search this Thread
Top Forums Programming perl script to create hash.
# 1  
Old 11-03-2011
perl script to create hash.

Hi,
I have the xml file file this, perl script to create hash<p>
Code:
<university>
<name>svu</name>
 <location>ravru</location>
 <branch>
   <electronics>
     <student name="xxx" number="12">
     <semester number="1"subjects="7" rank="2"/>
     </student>
     <student name="xxx" number="15">
     <semester number="1" subjects="7" rank="10"/>
     <semester number="2" subjects="4" rank="1"/>
      </student>
       <student name="xxx" number="16">
       <semester number="1"subjects="7" rank="2"/>
      <semester number="2"subjects="4" rank="2"/>
       </student>
    </electronics>
 </branch>
 </university>.
              . 
              .
              .
              .
              .
 <data>
 <student name="msr" number="1" branch="computers" />
 <student name="ksr" number="2" branch="electronics" />
<student name="lsr" number="3" branch="EEE" />
<student name="csr" number="4" branch="IT" />
<student name="msr" number="5" branch="MEC" />
<student name="ssr" number="6" branch="computers" />
<student name="msr" number="1" branch="CIV" />
.............................
..............................
.....................
</data>

how to create hash table for data elements. name and number as the key and branch is the value in that hash. why I need like this means some students have same name and some students have same number. by using this hash keys I have to search in the university node for student if found and print branch name of each student.

I written some script in XML::Simple but I am not able to create hash.</p>
Code:
#!/usr/bin/perl
use warnings;
use strict;
use Data::Dumper; 
use XML::Simple;

my $xml = new XML::Simple;
my $data = $xml->XMLin("data.xml", forcearray => [ 'student' , 'semister'],
                                                             
														     KeyAttr=>{student=>"+Name"});

print Dumper($data);


Last edited by veerubiji; 11-03-2011 at 06:15 PM..
# 2  
Old 11-06-2011
Quote:
Originally Posted by veerubiji
... name and number as the key and branch is the value in that hash...
What do you mean by "name and number as the key" ?
The hash key is a scalar, which means you cannot have both as the single key.

tyler_durden
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Perl: restrict perl from automaticaly creating a hash branches on check

My issue is that the perl script (as I have done it so far) created empty branches when I try to check some branches on existence. I am using multydimentional hashes: found it as the best way for information that I need to handle. Saing multidimentional I means hash of hashes ... So, I have ... (2 Replies)
Discussion started by: alex_5161
2 Replies

2. Shell Programming and Scripting

Dynamically parse BibTeX and create hash of hash

Hello gurus, Iam trying to parse following BibTex file (bibliography.bib): @book{Lee2000a, abstract = {Abstract goes here}, author = {Lee, Wenke and Stolfo, Salvatore J}, title = {{Data mining approaches for intrusion detection}}, year = {2000} } @article{Forrest1996, abstract =... (0 Replies)
Discussion started by: wakatana
0 Replies

3. Shell Programming and Scripting

Compare values of hashes of hash for n number of hash in perl without sorting.

Hi, I have an hashes of hash, where hash is dynamic, it can be n number of hash. i need to compare data_count values of all . my %result ( $abc => { 'data_count' => '10', 'ID' => 'ABC122', } $def => { 'data_count' => '20', 'ID' => 'defASe', ... (1 Reply)
Discussion started by: asak
1 Replies

4. Programming

CGI Perl script to execute bash script- unable to create folder

Hi I have a bash script which takes parameters sh /tmp/gdg.sh -b BASE-NAME -n 1 -s /source/data -p /dest/data/archive -m ARC gdg.sh will scan the /source/data and will move the contents to /dest/data/archive after passing through some filters. Its working superb from bash I have... (0 Replies)
Discussion started by: rakeshkumar
0 Replies

5. Shell Programming and Scripting

Remove default data hash sorting in perl script?

Hi, I have a datahash with 'n' number of values in perl script. I am writing a xml file from the datahash. I am getting output with sorting(Field sorting). My question is that i don't want any default sorting.whatever i am inserting into datahash it should give same xml file. Any help? ... (0 Replies)
Discussion started by: solo123
0 Replies

6. Shell Programming and Scripting

perl hash - using a range as a hash key.

Hi, In Perl, is it possible to use a range of numbers with '..' as a key in a hash? Something in like: %hash = ( '768..1536' => '1G', '1537..2560' => '2G' ); That is, the range operation is evaluated, and all members of the range are... (3 Replies)
Discussion started by: dsw
3 Replies

7. Shell Programming and Scripting

How to create hash dynamically in perl?

Hi, I have one file name file.txt It has the following contents: #File Contents StartTime,EndTime,COUNTER1,COUNTER2,COUNTER3 12:13,12:14,0,1,0 The output should be like this: StartTime: 12:13 ENDTIME: 12:14 (2 Replies)
Discussion started by: vanitham
2 Replies

8. Shell Programming and Scripting

Perl Hash:Can not keep hash data in the same order that it was inserted

Can Someone explain me why even using Tie::IxHash I can not get the output data in the same order that it was inserted? See code below. #!/usr/bin/perl use warnings; use Tie::IxHash; use strict; tie (my %programs, "Tie::IxHash"); while (my $line = <DATA>) { chomp $line; my(... (1 Reply)
Discussion started by: jgfcoimbra
1 Replies

9. Shell Programming and Scripting

passing a hash to another script in perl

I have a script (say script1.sh ) and I am calling a script (say script2.sh) within the script1.sh. Here in script1.sh I have a hash ( say %hash1) and i have to pass this hash to script2.sh. Basically i have to do some processing in Scirpt2.sh based on the hash(key,values). I wanted to know how can... (2 Replies)
Discussion started by: ammu
2 Replies

10. Shell Programming and Scripting

How to create md5 Hash variable?

I have a script that runs the grub-md5-crypt command based on whether the pass_value variable is a non-zero string. The md5 hash is being created in the /opt/hostconfigs/$HOST file, but I can't echo $md5_value. It is blank. Is there a way to create and echo a md5 hash variable? if then... (1 Reply)
Discussion started by: cstovall
1 Replies
Login or Register to Ask a Question