473,413 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

how to get the keys in a hash file in the same order?

Hi,
I have a hash in hash file in perl which looks some thing like this:
Expand|Select|Wrap|Line Numbers
  1. $FIELDS = {
  2.           'abc' => {
  3.         'Description' => {
  4.                             'Purpose' => 'some data is present',
  5.                             'Background' => 'something',
  6.                 }
  7.                  'Run Instructions' => {
  8.                             'Data' => 'something',
  9.                             'DEFAULT.INITIAL_WIPE' => 'somethng',
  10.                             'DEFAULT.SC_ON' => 'somethng',
  11.                  }
  12.                  'File' => '1',
  13.                  'Category => 'somethng',
  14.           },
  15.      'xyz' => {
  16.         'Description' => {
  17.                             'Purpose' => 'some data is present',
  18.                             'Background' => 'something',
  19.                 }
  20.                  'Run Instructions' => {
  21.                             'Data' => 'something',
  22.                             'DEFAULT.INITIAL_WIPE' => 'somethng',
  23.                             'DEFAULT.SC_ON' => 'somethng',
  24.                  }
  25.                  'File' => '2',
  26.                  'Category => 'somethng',
  27.           },
  28.           ............so on and so forth      
  29.       };
I want to display the values present in the inner hash i.e 'Description' and 'Run Instructions'.
I start off with somethng like this:
Expand|Select|Wrap|Line Numbers
  1. %mydata = $FIELDS;
  2. foreach my $key (sort {$myData{$a}{Category} cmp $myData{$b}{Category} or
  3.                       $myData{$a}{File} cmp $myData{$b}{File}} keys %myData) {
  4. .....................
  5. ..................
  6.       if ($myData{$key}{'Description'}){
  7.             print "<br><b>Description:</b><br>";
  8.             my $counterdesc = $myData{$key}{'Description'};
  9.             %desc = %$counterdesc;
  10.             while (($keydatadesc,$valuedatadesc) = each(%desc)) {
  11.                 if ($keydatadesc =~ /^Data$/) {
  12.                     print $valuedatadesc."<br>";
  13.                 }
  14.             }
  15.             foreach my $keydesc (keys %desc) {
  16.                 if ($keydesc !~ /^Data$/) {
  17.                     print "<font   
  18.                                         color=blue><b>$keydesc:</b></font><br>";
  19.                     if ($desc{$keydesc} !~ /^$/) {
  20.                         print $desc{$keydesc}."<br>";
  21.                     }
  22.                     else {
  23.                         print $desc{$keydesc}."<br><br>";
  24.                     }
  25.                 }
  26.             }
  27.         }
  28. ......Somethng for Run Instruction also
  29. .....
  30. }
The problem is that while I run the loop to display the items present in 'Description' I dont get the keys in the order they are present in the hash file i.e if for the hash 'abc' ,I want 'Purpose' first followed by 'Background'...But while sorting the order gets shuffled...and I end up getting the information but the keys are shuffled..I also dont want to sort it as that does not fulfill my requirement.
I want the keys present in the inner hash exactly in the same order as it is present in the file..

Please reply as soon as possible...
Nov 14 '08 #1
5 2539
KevinADC
4,059 Expert 2GB
There is no urgent help here so in the future don't ask for it.

If you want to maintain order, use an array to store the hash keys you want to display in a certain order.
Nov 14 '08 #2
Hi Kevin,
I tried doin it in the array...But stil the problem did not resolve..I figured out tht there is some problem while I dereference the hash 'Description'.M working on that..

Thanks..
Nov 14 '08 #3
KevinADC
4,059 Expert 2GB
When you want help with your code, post it.
Nov 14 '08 #4
Hey kevin,
Thanks for the reply.Next time I shall post the code...
I got the solution for the problem...
Thnks again for the help!!!!
Nov 15 '08 #5
KevinADC
4,059 Expert 2GB
Hey kevin,
Thanks for the reply.Next time I shall post the code...
I got the solution for the problem...
Thnks again for the help!!!!
Well, considering I was no help to you that I can see, you're very welcome.
Nov 15 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: | last post by:
The data file is a simple Unicode file with lines of text. BCP apparently doesn't guarantee this ordering, and neither does the import tool. I want to be able to load the data either sequentially...
5
by: tilak.negi | last post by:
We have one single hash (#) table, in which we insert data processing priority wise (after calculating priority). for. e.g. Company Product Priority Prod. Qty Prod_Plan_Date C1...
4
by: Sebastian Dau | last post by:
Hello, I'm writing a security related application in .NET 1.1 and I wonder how I compute hashes from very large files (up to 1 GB). Does anybody know a good pattern of how to create a stream...
8
by: spohle | last post by:
hi i have a normal dictionary with key and value pairs. now i wanna sort by the keys BUT in a specific order i determine in a list !? any ideas dic = {'key1':'value1', 'key2':'value2',...
24
by: kdotsky | last post by:
Hello, I am using some very large dictionaries with keys that are long strings (urls). For a large dictionary these keys start to take up a significant amount of memory. I do not need access to...
4
by: blackice | last post by:
Hello All, i have a Perl Script that deleting Zones from named.conf file and here is the script #!/usr/bin/perl -w use strict; print "please enter the domain name: "; chomp (my...
0
by: Emily Wang | last post by:
I have a code package, whick can be compiled, run correctly on linux, but I have to transplant it to windows vc 2005 Some problems arrise, it is not compatible... I need a compatible hash file...
0
by: Protim | last post by:
How can I read a hash file using C#
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.