473,503 Members | 241 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help On Hashes

rajiv07
141 New Member
Hi to all,

How do i print the hashes in the stored manner.because when i print the hash value it print random order by default. But i want the value by the stored
manner.

Here i am using this hash

Expand|Select|Wrap|Line Numbers
  1. my %status=('Payment Received'=>PR,'Order Under processing'=>'Under processing','Shipped From WareHouse'=>SWH,Courier=>C,Delivered=>D);
  2.  
  3.  or $key(keys %status)
  4.  {
  5.   print "$key \t $status{$key}";
  6.   print "\n";
  7.  }
  8.  
The output will be

Delivered D
Order Under processing Under processing
Payment Received PR
Courier C
Shipped From WareHouse SWH

But I want

Payment Received PR
Order Under processing Under processing
Shipped From WareHouse SWH
Courier C
Delivered D


Thanks

Regards
Rajiv
Dec 10 '07 #1
8 1634
mehj123
55 New Member
Hi to all,

How do i print the hashes in the stored manner.because when i print the hash value it print random order by default. But i want the value by the stored
manner.

Here i am using this hash

Expand|Select|Wrap|Line Numbers
  1. my %status=('Payment Received'=>PR,'Order Under processing'=>'Under processing','Shipped From WareHouse'=>SWH,Courier=>C,Delivered=>D);
  2.  
  3.  or $key(keys %status)
  4.  {
  5.   print "$key \t $status{$key}";
  6.   print "\n";
  7.  }
  8.  
The output will be

Delivered D
Order Under processing Under processing
Payment Received PR
Courier C
Shipped From WareHouse SWH

But I want

Payment Received PR
Order Under processing Under processing
Shipped From WareHouse SWH
Courier C
Delivered D


Thanks

Regards
Rajiv
Hi Rajiv,
Why dont you use keys like 1,2,3 etc and let these keys point to the values.i.e
Expand|Select|Wrap|Line Numbers
  1. 1=>PR,
  2. 2=>Under processing etc
and in your code replace '1' by Payment Received.. I think you can maintain the order of addition by this way only.
To make it simpler you can use the Tie::IxHash module. See the example here
Dec 10 '07 #2
rajiv07
141 New Member
Thank U mehj123.Let me try and i will report the status to u.

regards
Rajiv
Dec 10 '07 #3
numberwhun
3,509 Recognized Expert Moderator Specialist
Hi to all,

How do i print the hashes in the stored manner.because when i print the hash value it print random order by default. But i want the value by the stored
manner.

Here i am using this hash

Expand|Select|Wrap|Line Numbers
  1. my %status=('Payment Received'=>PR,'Order Under processing'=>'Under processing','Shipped From WareHouse'=>SWH,Courier=>C,Delivered=>D);
  2.  
  3.  or $key(keys %status)
  4.  {
  5.   print "$key \t $status{$key}";
  6.   print "\n";
  7.  }
  8.  
The output will be

Delivered D
Order Under processing Under processing
Payment Received PR
Courier C
Shipped From WareHouse SWH

But I want

Payment Received PR
Order Under processing Under processing
Shipped From WareHouse SWH
Courier C
Delivered D


Thanks

Regards
Rajiv
What you have to realize is that a hash is NOT an array. It is a list of key=>value pairs with no specific order. How you added to the list does not impact how the values are stored or returned to you.

You can sort a hash, but it won't be in the order you added them. Here is one link that can tell you a little about hashes, but I would seriously consider getting the "Learning Perl" book (Llama book) and reading its information as it is quite helpful.

Regards,

Jeff
Dec 10 '07 #4
KevinADC
4,059 Recognized Expert Specialist
use an array to store the hash keys in the order you want to display them:

Expand|Select|Wrap|Line Numbers
  1. my @keys = ('Payment Received', 'Order Under processing', 'Shipped From WareHouse', 'Courier', 'Delivered')
  2.  
  3. my %status=('Payment Received'=>PR,'Order Under processing'=>'Under processing','Shipped From WareHouse'=>SWH,Courier=>C,Delivered=>D); 
  4.  
  5. foreach my $key (@keys) {
  6.    print "$key = $status{$key}\n";
  7. }
Dec 11 '07 #5
mehj123
55 New Member
use an array to store the hash keys in the order you want to display them:

Expand|Select|Wrap|Line Numbers
  1. my @keys = ('Payment Received', 'Order Under processing', 'Shipped From WareHouse', 'Courier', 'Delivered')
  2.  
  3. my %status=('Payment Received'=>PR,'Order Under processing'=>'Under processing','Shipped From WareHouse'=>SWH,Courier=>C,Delivered=>D); 
  4.  
  5. foreach my $key (@keys) {
  6.    print "$key = $status{$key}\n";
  7. }
Wow... this is clean and simple to understand also..... A lot better than my 1,2,3.... :) Thanks
Dec 11 '07 #6
KevinADC
4,059 Recognized Expert Specialist
Wow... this is clean and simple to understand also..... A lot better than my 1,2,3.... :) Thanks
Using numbered hash keys is really sort of using the wrong tool for the job, you may as well just use an array and use the numbers as the index value of each element of the array and then you automatically have an ordered list. Then call each array element using its index number instead of a numbered hash key. But you could use numbers for the hash keys if you really wanted to.
Dec 11 '07 #7
ntraj
1 New Member
hey
first u say clearly wat u want?

y u confused?
Dec 14 '07 #8
KevinADC
4,059 Recognized Expert Specialist
hey
first u say clearly wat u want?

y u confused?
Clearly? Look at what you posted, it's about as clear as mud. If you wish to particpate and help, please do, but posting dumb comments written like you are talking to your myspace "friends" are not welcome.
Dec 14 '07 #9

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

Similar topics

0
1535
by: Carl S. in 't Veld | last post by:
I am trying to generate tiger tree hashes the same way as directconnect does, but I am failing. I checked the output from php with the reference vectors from...
0
1262
by: Jonathan Hayward | last post by:
I'm trying to have a client open a socket, send two pickled hashes, and receive a pickled object (I'm also writing the server, to listen, read two pickled hashes, and send a pickled object). I've...
8
2735
by: Ben Holness | last post by:
Hi All, I want to create a hash array, based on values in a database. Basically, I want a hash array for each database key and I want to use a sub to get the hash array, but I am having a great...
3
4677
by: kevin | last post by:
Is that even possible? I am creating a web service in .NET to expose some already created .NET programs to other groups. One group is writing the client in PERL, and thus wishes the wsdl schema...
8
3529
by: MuZZy | last post by:
Hi, Why for god sake they change implementation of String.GetHashCode() from ..NET 1 to .NET 2? We were storing some user passwords in hashcode, now we can't upgrade those clients with .NET 2...
2
2842
by: MartyNg | last post by:
I am running a system that has both Classic ASP applications and a smattering of ASP.NET applications. We want to store passwords on a SQL Server table as their MD5 hashes. What is the safest...
5
2642
by: EP | last post by:
This inquiry may either turn out to be about the suitability of the SHA-1 (160 bit digest) for file identification, the sha function in Python ... or about some error in my script. Any insight...
7
1905
numberwhun
by: numberwhun | last post by:
Hello all! I am working on trying to figure out how to print out a hash of hashes. How the hash in the code is defined below is very similar to how the hash is defined in the script I am...
6
9593
KevinADC
by: KevinADC | last post by:
This snippet of code provides several examples of programming techniques that can be applied to most programs. using hashes to create unique results static variable recursive function...
0
7089
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
7339
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7463
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
5581
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,...
1
5017
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
4678
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...
0
3168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3157
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
738
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.