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 - my %status=('Payment Received'=>PR,'Order Under processing'=>'Under processing','Shipped From WareHouse'=>SWH,Courier=>C,Delivered=>D);
-
-
or $key(keys %status)
-
{
-
print "$key \t $status{$key}";
-
print "\n";
-
}
-
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
8 1634
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 - my %status=('Payment Received'=>PR,'Order Under processing'=>'Under processing','Shipped From WareHouse'=>SWH,Courier=>C,Delivered=>D);
-
-
or $key(keys %status)
-
{
-
print "$key \t $status{$key}";
-
print "\n";
-
}
-
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 - 1=>PR,
-
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
Thank U mehj123.Let me try and i will report the status to u.
regards
Rajiv
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 - my %status=('Payment Received'=>PR,'Order Under processing'=>'Under processing','Shipped From WareHouse'=>SWH,Courier=>C,Delivered=>D);
-
-
or $key(keys %status)
-
{
-
print "$key \t $status{$key}";
-
print "\n";
-
}
-
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
KevinADC 4,059
Recognized Expert Specialist
use an array to store the hash keys in the order you want to display them: - my @keys = ('Payment Received', 'Order Under processing', 'Shipped From WareHouse', 'Courier', 'Delivered')
-
-
my %status=('Payment Received'=>PR,'Order Under processing'=>'Under processing','Shipped From WareHouse'=>SWH,Courier=>C,Delivered=>D);
-
-
foreach my $key (@keys) {
-
print "$key = $status{$key}\n";
-
}
use an array to store the hash keys in the order you want to display them: - my @keys = ('Payment Received', 'Order Under processing', 'Shipped From WareHouse', 'Courier', 'Delivered')
-
-
my %status=('Payment Received'=>PR,'Order Under processing'=>'Under processing','Shipped From WareHouse'=>SWH,Courier=>C,Delivered=>D);
-
-
foreach my $key (@keys) {
-
print "$key = $status{$key}\n";
-
}
Wow... this is clean and simple to understand also..... A lot better than my 1,2,3.... :) Thanks
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.
hey
first u say clearly wat u want?
y u confused?
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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...
|
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...
| |
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...
|
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,...
|
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...
|
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: 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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |