Thanks for your help, I will look carefully at both of your comments.
cheers
From: John W. Krahn jwkr...@shaw.ca
To: Perl Beginners beginners@perl.org
Sent: Friday, 13 April 2012 6:08 AM
Subject: Re: Array of Hashes
Rob Dixon wrote:
Hi Paul and welcome
Hi All
New to this group, so hello to everybody.
I am currently working on creating a Array of Hashes, note it is a work in
progress. I
appear to be getting some corruption when inputting data with the pvdisplay, I
can't see why this is the case. I have put
some print statements to see where I
beginners@perl.org
Sent: Thursday, 12 April 2012 9:48 PM
Subject: Array of Hashes
Hi All
New to this group, so hello to everybody.
I am currently working on creating a Array of Hashes, note it is a work in
progress. I
appear to be getting some corruption when inputting data with the pvdisplay, I
On 12/04/2012 12:48, Paul.G wrote:
Hi All
New to this group, so hello to everybody.
I am currently working on creating a Array of Hashes, note it is a
work in progress. I appear to be getting some corruption when
inputting data with the pvdisplay, I can't see why this is the case.
I have put
Rob Dixon wrote:
Hi Paul and welcome to the list.
I can see a few things wrong with your code, but I have only a Windows
machine so cannot test any changes I am suggestion so please beware.
The reason you get the marked line in your output is because that is
what you have written. This loop
Hi all,
I am getting a syntax error with the following code:
Line 10: @snmpSessions = (%snmpSession1, %snmpSession2);
Line 11: foreach %snmpSession (@snmpSessions)
Line 12: {
Line 13:# The following is call to my own subroutine that has
been tested and it works (:-)
Line 14:
On Sat, Jul 19, 2008 at 2:45 PM, Bobby Jafari [EMAIL PROTECTED]
wrote:
Hi all,
I am getting a syntax error with the following code:
Line 10: @snmpSessions = (%snmpSession1, %snmpSession2);
Line 11: foreach %snmpSession (@snmpSessions)
Line 12: {
Line 13:# The following is call to
Thanks heaps. Problem solved.
code changed to
Line 10: @snmpS = (\%snmpSession1, \%snmpSession2);
Line 11: foreach $snmpS (@snmpSessions)
Line 12: {
Line 13:ethernetGlobalMode ($snmpS);
Line 14: }
On Feb 21, 9:46 am, [EMAIL PROTECTED] (Chas. Owens) wrote:
On Wed, Feb 20, 2008 at 11:03 PM, [EMAIL PROTECTED] wrote:
snip Oh - I wanted to eliminate all members of the array that had more than
10 instances of the same port. I was hoping that you could do
something like count keys
Hi, thank you all for your input - I managed to get what I wanted
done. Sorry I was not very clear on the issue, but it helped to write
it out.
Jim
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/
I have a feeling that I am going about this in the wrong
way. Can I use hashes in a better way to sort the data based on the
keys? Better yet, can I evaluate the number of keys that match each
other?
I don't understand what that means.
John
Oh - I wanted to eliminate all members of the
On Feb 20, 10:26 pm, [EMAIL PROTECTED] wrote:
Hi, thank you all for your input - I managed to get what I wanted
done. Sorry I was not very clear on the issue, but it helped to write
it out.
Jim
Please ignore this post ^, I do not have a end solution yet.
--
To unsubscribe, e-mail: [EMAIL
On Wed, Feb 20, 2008 at 11:03 PM, [EMAIL PROTECTED] wrote:
snip
Oh - I wanted to eliminate all members of the array that had more than
10 instances of the same port. I was hoping that you could do
something like count keys where port = gi1/1/49. After knowing how
many gi1/1/49 there
I am reading in a file, building an array of information that I need
to evaluate:
while (FILE) {
if ($_ =~ m/stuff/) {
push(@data, {'vlan' = $vlan, 'host' = $host, 'mac' = $mac, 'port'
= $port});
}
}
Small sample of @data:
vlan hostmacport
13 switch-1
[EMAIL PROTECTED] wrote:
I am reading in a file, building an array of information that I need
to evaluate:
while (FILE) {
if ($_ =~ m/stuff/) {
push(@data, {'vlan' = $vlan, 'host' = $host, 'mac' = $mac, 'port'
= $port});
}
}
Small sample of @data:
vlan hostmac
On Feb 19, 2008 11:12 PM, [EMAIL PROTECTED] wrote:
I am reading in a file, building an array of information that I need
to evaluate:
while (FILE) {
if ($_ =~ m/stuff/) {
push(@data, {'vlan' = $vlan, 'host' = $host, 'mac' = $mac, 'port'
= $port});
}
}
Small sample of @data:
vlan
On Aug 7, 7:47 pm, [EMAIL PROTECTED] (Chris Cosner) wrote:
I've re-read perlref and have been trying to tease an answer out of the
Perl Cookbook.
If you put a hash reference into an array
push @array, \%hash;
you do not store any actual hash data in the array.
So if you change the
I've re-read perlref and have been trying to tease an answer out of the
Perl Cookbook.
If you put a hash reference into an array
push @array, \%hash;
you do not store any actual hash data in the array.
So if you change the hash, then later pull the hash reference from the
array and access
Chris Cosner wrote:
If you put a hash reference into an array
push @array, \%hash;
you do not store any actual hash data in the array.
So if you change the hash, then later pull the hash reference from the
array and access it, you get changed data.
push @array, { %hash };
This creates an
I've re-read perlref and have been trying to tease an answer out of the
Perl Cookbook.
If you put a hash reference into an array
push @array, \%hash;
you do not store any actual hash data in the array.
So if you change the hash, then later pull the hash reference from the
array and
Aha. Many thanks.
Now I'm on the right track (see Anonymous Data in the Perl Cookbook, ch.
11).
Mr. Shawn H. Corey wrote:
Chris Cosner wrote:
If you put a hash reference into an array
push @array, \%hash;
you do not store any actual hash data in the array.
So if you change the hash, then
I have a problem with extracting an individual hash from an array of
hashes. I can't work out, or find elsewhere, the syntax for this.
Code as follows:
devices_array_oH is set up as array of hashes
I want to loop over all hashes in the array and to print the key value pairs for
each hash
On Aug 7, 7:59 am, [EMAIL PROTECTED] (Charles J Gillan) wrote:
I have a problem with extracting an individual hash from an array of
hashes. I can't work out, or find elsewhere, the syntax for this.
The syntax is found in
perldoc perlref
perldoc perlreftut
perldoc perllol
and
perldoc perldsc
Paul Lalli wrote:
I would have written the program like this:
my $itemp = 1;
foreach my $device_hash_ref (@devices_array_oH) {
print Details of device $itemp: ;
print \n\n;
foreach my $key (keys %{$device_hash_ref})
{
print ( $key \t $device_hash{$key} \n);
On Aug 7, 8:29 am, [EMAIL PROTECTED] (Mr. Shawn H. Corey) wrote:
Paul Lalli wrote:
foreach my $key (keys %{$device_hash_ref})
{
print ( $key \t $device_hash{$key} \n);
print ( $key \t $device_hash_ref-{$key} \n);
Whoops! Quite correct. Thanks for catching
On Jul 11, 9:04 pm, [EMAIL PROTECTED] (Paul Lalli) wrote:
If you have access to the server logs, check them. If not, add this
line to the top of your program, right under use strict and use
warnings:
use CGI::Carp qw/fatalsToBrowser/;
Paul Lalli
Thanks Paul, it's nice to have error
Hi,
I would like to make a perl module with an array of hashes as the data
structure, but I am having trouble with the references. I have
declared the data structure in the constructor as follows:
my $self = ({});
and blessed it with:
bless ($self, $class_name);
but when I try
Inventor wrote:
Hi,
I would like to make a perl module with an array of hashes as the data
structure, but I am having trouble with the references. I have
declared the data structure in the constructor as follows:
my $self = ({});
my $self = [];
and blessed it with:
bless
On Jul 11, 3:33 pm, [EMAIL PROTECTED] (Inventor) wrote:
the program gets a run-time error, and I don't know which error
message it is because the module is used in a CGI program and I don't
know how to get at the error messages.
If you have access to the server logs, check them. If not, add
From: pauld [EMAIL PROTECTED]
ive read a load of data in from a CSV file with Text::CSV and ended
up with a hash (%hash) where the keys are the column labels.
my @headings=split(/,/,$rows[0])
and then
for (my $j=1;$j$#rows;$j++)
{
my $status = $csv-parse ($rows[$j]); # parse a CSV
thanks for the help - im looking up hash slices - but id like to get
something that works and then i can add new ideas etc so im going to
leave it as it for the time being.
Data::Dumper has helped sort out where an error is coming
#!/usr/bin/perl -w
use strict;
use warnings;
open O, $file or
On May 27, 4:37 pm, [EMAIL PROTECTED] (Pauld) wrote:
thanks for the help - im looking up hash slices -
perldoc perldata
Entire arrays (and slices of arrays and hashes) are denoted
by '@', which works much like the word these or those
does in English, in that it indicates multiple
ive read a load of data in from a CSV file with Text::CSV and ended
up with a hash (%hash) where the keys are the column labels.
my @headings=split(/,/,$rows[0])
and then
for (my $j=1;$j$#rows;$j++)
{
my $status = $csv-parse ($rows[$j]); # parse a CSV string into
fields
my @columns =
On May 26, 8:17 am, [EMAIL PROTECTED] (Pauld) wrote:
ive read a load of data in from a CSV file with Text::CSV and ended
up with a hash (%hash) where the keys are the column labels.
my @headings=split(/,/,$rows[0])
You're use()'ing Text::CSV, but you're not actually using Text::CSV.
Why?
a hash of an array of hashes
ive read a load of data in from a CSV file with Text::CSV and ended
up with a hash (%hash) where the keys are the column labels.
my @headings=split(/,/,$rows[0])
and then
for (my $j=1;$j$#rows;$j++)
{
my $status = $csv-parse ($rows[$j]); # parse a CSV string
]
To: pauld [EMAIL PROTECTED]
Cc: beginners beginners@perl.org
Sent: 19:47:38 (GMT+0200) Africa/Harare שבת 26 מאי 2007
Subject: Re: accesing a hash of an array of hashes
Hi,
To access element of a given DATE (sat ... date_inp) from Hofdates you can do
the following:
my $date_inp = ... ;
die
On 05/26/2007 07:17 AM, pauld wrote:
ive read a load of data in from a CSV file with Text::CSV and ended
up with a hash (%hash) where the keys are the column labels.
my @headings=split(/,/,$rows[0])
and then
for (my $j=1;$j$#rows;$j++)
{
my $status = $csv-parse ($rows[$j]); # parse a CSV
On May 26, 1:51 pm, [EMAIL PROTECTED] (Mumia W.)
wrote:
On 05/26/2007 07:17 AM, pauld wrote:
ive read a load of data in from a CSV file with Text::CSV and ended
up with a hash (%hash) where the keys are the column labels.
my @headings=split(/,/,$rows[0])
and then
for (my
I have a program which I am working on which has several different
packages. One of these packages, FluxDB.pm, creates an array of hashes
called @users. Each element is a hash containing (among other things)
username and uid (primary key from the DB this is generated out of).
In another package
On 8/21/06, Andy Greenwood [EMAIL PROTECTED] wrote:
I have a program which I am working on which has several different
packages. One of these packages, FluxDB.pm, creates an array of hashes
called @users. Each element is a hash containing (among other things)
username and uid (primary key from
I am creating a phone directory and would like to display the entire
contents of the database ordered by last name utilizing the
HTML:Template module. I am not sure the code that I have so far will
work as I have planned as this is my first time ever using an array of
hashes. How can I be sure
Hi all, I need to loop over an array of hashes and assign a new hashref if a
condition is met:
I have a scalar which contains an array of hashes:
$locations = [
{
'location_name' = 'Fionas House',
'location_id' = '0027
On Fri, 2006-28-04 at 15:40 +0100, Graeme McLaren wrote:
Hi all, I need to loop over an array of hashes and assign a new hashref if a
condition is met:
I have a scalar which contains an array of hashes:
$locations = [
{
'location_name' = 'Fionas House
Hi All
Can anyone tell me whether there is any way for declaring an array of
hashes similar to creating array of structure variables in C
programming?
Thanks
Best regards
Bala
The information contained in this electronic message and any attachments to
this message are intended
[EMAIL PROTECTED] wrote:
Hi All
Can anyone tell me whether there is any way for declaring an array of
hashes similar to creating array of structure variables in C
programming?
There is a module, Class::Struct, that might be what you want. See
`perldoc Class:Struct`.
However, I would
Morning all, I have a problem that I can't see a way around. Basically I
have an array of hashes and I want to get the key and value of each hash but
with the following code I'm getting:
Type of arg 1 to keys must be hash (not array element) at
/usr/lib/perl5/vendor_perl/Purchaser/Common.pm
an array of hashes and I want to get the key and value of each hash
but
with the following code I'm getting:
Type of arg 1 to keys must be hash (not array element) at
/usr/lib/perl5/vendor_perl/Purchaser/Common.pm line 477, near ])
#code:
foreach my $key (keys $AoH[$map_loop{$i
How can I do this correctly?
foreach my $col (@columns) {
my %{$col} = (
string = $col,
number = [EMAIL PROTECTED]
);
push (@graph, \%{$col});
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For
Ryan Perry mailto:[EMAIL PROTECTED] wrote:
: How can I do this correctly?
:
:
: foreach my $col (@columns) {
:my %{$col} = (
: string = $col,
: number = [EMAIL PROTECTED]
: );
:push
On Monday 15 August 2005 22.47, Ryan Perry wrote:
How can I do this correctly?
foreach my $col (@columns) {
my %{$col} = (
string = $col,
number = [EMAIL PROTECTED]
);
push (@graph,
How can I do this correctly?
foreach my $col (@columns) {
my %{$col} = ( # -- I have a problem here, I want
the hash to be named whatever $col is
string = $col,
number = [EMAIL PROTECTED]
);
On Mon, Aug 15, 2005 at 04:08:22PM -0500, The Ghost wrote:
How can I do this correctly?
foreach my $col (@columns) {
my %{$col} = ( # -- I have a problem here, I want
the hash to be named whatever $col is
string = $col,
The Ghost wrote:
How can I do this correctly?
foreach my $col (@columns) {
my %{$col} = ( # -- I have a problem here, I want the
hash to be named whatever $col is
string = $col,
number = [EMAIL PROTECTED]
Hello
I have a situation where I build an anonymous array of hashes for some requests
and responses found in a file (there can be multiple requests and responses).
It works very nicely and tracks all of the responses and requests from an ip to
another IP address.
Here is my code:
my $time=$1
Hello
I have a situation where I build an anonymous array of hashes for some
requests and responses found in a file (there can be multiple requests and
responses). It works very nicely and tracks all of the responses and
requests from an ip to another IP address.
Here is my code:
my $time=$1
On Friday 05 August 2005 01:37, Jason Normandin wrote:
[..]
if ($protocol =~ /PING REQUEST/) {
push @{$pingRequests{$destination}}, {
time = $time,
sequenceNumber=$sequenceNumber
};
}
elsif ($protocol =~ /PING RESPONSE/) {
push
Jason Normandin wrote:
Hello
Hello,
I have a situation where I build an anonymous array of hashes for some
requests and responses found in a file (there can be multiple requests and
responses). It works very nicely and tracks all of the responses and
requests from an ip to another IP
How can I get the information out of the hashes?
sub somthing {
while (my $ref = $sth-fetchrow_hashref()) {
foreach my $col (keys %{$ref}) {
$results[$x]{$col}=$ref-{$col};
}
$x++;}
return (@results); }
Then later:
(I don't understand this part)
foreach my
The Ghost wrote:
How can I get the information out of the hashes?
sub somthing {
while (my $ref = $sth-fetchrow_hashref()) {
foreach my $col (keys %{$ref}) {
$results[$x]{$col}=$ref-{$col};
}
$x++;}
return (@results); }
Then later:
(I don't understand this part)
On Jul 13, The Ghost said:
foreach my $col (keys %{$ref}) {
$results[$x]{$col}=$ref-{$col};
}
$x++;}
The @results array holds hash references...
foreach my $result (@results) {
foreach my $key (keys {$results[$x]}) {
Here you want to do:
foreach my $key
Jeff 'japhy' Pinyan wrote:
Here you want to do:
foreach my $key (keys %$result) {
since each element in @results is a hash-ref, and $result is an element
from @results, you need to gets its keys. Since $result is a hash
reference, you need to write %$result to get at the hash.
Hi all,
I have the following code below which I need to modify a bit.
The script currently lists the key/value pairs for all processes in the
system.
What I need to achieve is for it to only list the key/value pairs for
processes of which the Description key is of a certain ASCII value, say
On Thu, 31 Mar 2005 14:40:47 +0200, Olivier, Wim W wrote:
Hi all,
I have the following code below which I need to modify a bit.
The script currently lists the key/value pairs for all processes in the
system.
What I need to achieve is for it to only list the key/value pairs for
processes
Thanks Offer! It's working!
Wim
-Original Message-
From: Offer Kaye [mailto:[EMAIL PROTECTED]
Sent: 31 March 2005 02:55 PM
To: Perl Beginners
Subject: Re: Question: Array of Hashes
On Thu, 31 Mar 2005 14:40:47 +0200, Olivier, Wim W wrote:
Hi all,
I have the following code below
Hey all I'm stuck looping through an array of hashes, here is what I have:
##
for my $a (@result){
for my $h (keys %$a){
$tst = $h-{$a};
}
}
##
@result contains a hashes, I can die it out ok... there is something
wrong when I try looping
Ok everyone I got it:
for my $a (@result){
for my $h (keys %$a){
print $h = $a-{$h} BRBRBR;
}
}
Cheers,
G :)
From: Graeme McLaren [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Subject: array of hashes looping prob
Date: Mon, 04 Oct 2004 10:27:37 +0100
MIME-Version: 1.0
X-Originating-IP
From: Graeme McLaren mailto:[EMAIL PROTECTED] wrote:
: Ok everyone I got it:
:
: for my $a (@result){
:
: for my $h (keys %$a){
:
: print $h = $a-{$h} BRBRBR;
: }
: }
Avoid using $a and $b as variables. They are used
by 'sort' and treated special by perl. Use descriptive
the database, I'm creating an
Array of Hashes and displaying the data. The pertinent code follows:
while (@row = $sth-fetchrow_array()) {
$count ++;
$id = $row[0];
$AoH[$count]{id} = $row[0];
$AoH[$count]{transstatus} = $row[7];
my $b1 = $f1-Button(-text = 'Update', -command
-Original Message-
From: Chris Mortimore [mailto:[EMAIL PROTECTED]
Sent: Thursday, August 05, 2004 5:19 PM
To: [EMAIL PROTECTED]
Subject: Sorting an array of hashes
I want to sort an AoH. Not each hash by its keys, but the array by the
value of one of the keys in each hash. I know how
I want to sort an AoH. Not each hash by its keys, but the array by the
value of one of the keys in each hash.
I know how to sort a simple array.
I know how to sort a hash by the keys.
Could someone kindly point me to the documentation on sorting arrays of
hashes?
Thank you!
Chris.
- -
Chris Mortimore wrote:
I want to sort an AoH. Not each hash by its keys, but the array by
the value of one of the keys in each hash.
The value of one of the keys? If you don't know *which* key in
respective hash, this appears to be pretty tricky...
--
Gunnar Hjalmarsson
Email:
://www.gunnar.cc/cgi-bin/contact.pl
--
Of course I know _which_ key. Each hash has a key date_tm, I want to
sort all the hashes in the array by their date_tm value which is in the
format: mmdddhhmm.
Chris.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL
, this appears to be pretty tricky...
Of course I know _which_ key. Each hash has a key date_tm, I want
to sort all the hashes in the array by their date_tm value which is in
the format: mmdddhhmm.
Don't you think it might have been constructive to mention this the
first time around?
Can you please
-Original Message-
From: Chris Mortimore [mailto:[EMAIL PROTECTED]
Sent: Thursday, August 05, 2004 5:19 PM
To: [EMAIL PROTECTED]
Subject: Sorting an array of hashes
I want to sort an AoH. Not each hash by its keys, but the array by the
value of one of the keys in each hash.
I know how
On 8/5/2004 5:18 PM, Chris Mortimore wrote:
I want to sort an AoH. Not each hash by its keys, but the array by the
value of one of the keys in each hash.
I know how to sort a simple array.
I know how to sort a hash by the keys.
Could someone kindly point me to the documentation on sorting arrays
...
Of course I know _which_ key. Each hash has a key date_tm, I
want to sort all the hashes in the array by their date_tm value
which is in the format: mmdddhhmm.
Aha, the keys have the same name.. Good! Then Randy's suggested code
should do.
As regards documentation, besides perldoc -f sort
Is there a way I can explictly declare that each array
cell contains a hash?
Here is the only way I know to do it:
my @PCEs=[];
while ($Data-FetchRow()) {
my %dh = $Data-DataHash();
$PCEs[$cn]{$dh{id}} = $dh{ridPCE};
}
This my declaration only says that it is an array,
not an array
that it is an array,
not an array of hashes. Can I improve upon this?
Why would you want to declare this? Since the anonymous hashes spring into existence automatically, no declaration is necessary.
To access an element of your referenced hash, you have to add another scalar symbol like this:
$$PCEs
the value you
are assigning which
will cause your array to have one value, the last.
If you are changing
$cn in the DataHash method you shouldn't be and have
broken the
encapsulation, but that is a design issue.
}
This my declaration only says that it is an
array,
not an array of hashes. Can I
Wiggins d'Anconia wrote:
Jan Eden wrote:
$$PCEs[$cn]{$dh{id}} ...
Adding an extra $ here causes Perl to look for $PCEs a scalar, which
doesn't exist rather than dereference the PCEs array.
Ok, I thought of a construction like
$ {$PCEs[$cn]} {$dh{id}} ...
This should be equivalent to the
Hi John,
I received your code. Thanks.
I would like to know how to check the values of the keys in the hash. I
checked the Perl cookbook and It showed me how to get the key value pairs
and print them, but I am not familiar with populating an array with a hash,
or how to
dynamically print the
Hi William,
This is very simple. The key function will do the work as in this example:
my %hash;
my @keys;
my @values;
$hash{key1} = value1;
$hash{key2} = value2;
foreach my $key (keys %hash) {
push(@keys,$key);
push(@values,$hash{$key});
}
After the execution of this script
with a hash,
or how to dynamically print the values out.
I was only using an array of hashes because you used that in your code.
If you are having problems with Perl's data structures have a look at
the fine documentation:
perldoc perldata
perldoc perldsc
perldoc perllol
A handy module for displaying
Terrific. Thank you. Thank you. Thank you.
- Original Message -
From: John W. Krahn [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Tuesday, December 23, 2003 4:19 PM
Subject: Re: Printing Array of Hashes
William Martell wrote:
Hi John,
Hello,
I received your code. Thanks
Hi experts,help!!
I am reading data from a text file and storing the data in an array of hashes and hash
of hashes.I dont know how and where I need to pass the reference into the array and
hash and dereference it.
The purpose of the code is to read data by column names and compare each record
Hi
I want to put a hash into each element of an array. I do it like the following bit of
code. When I iterate round my hash before putting it in the array of the hash
values/keys are there. However, when I iterate through the hash after putting it in
the array all i get is '4/8' as the
]]
Sent: Wednesday, September 18, 2002 9:06 AM
To: [EMAIL PROTECTED]
Subject: Array of Hashes
Hi
I want to put a hash into each element of an array. I do it
like the following bit of code. When I iterate round my hash
before putting it in the array of the hash values/keys
: RE: Array of Hashes
18/09/2002 14:11
[mailto:[EMAIL PROTECTED]]
Sent: Wednesday, September 18, 2002 3:18 PM
To: Nikola Janceski nikola_janceski; [EMAIL PROTECTED]
Subject: RE: Array of Hashes
Apologies, that was bad typing in my email. I rearrange the algorithm to make it
easier to read. Here is my exact source and the exact
On Wed, 18 Sep 2002, Simon Tomlinson wrote:
Apologies, that was bad typing in my email. I rearrange the algorithm to make it
easier to read. Here is my exact source and the exact output. Even without the
space there, it still doesn't work!!
Any ideas?
Simon.
sub getEvents
{
]
[EMAIL PROTECTED]cc:
.comSubject: RE: Array
Simon Tomlinson wrote:
Hi
I want to put a hash into each element of an array. I do it like the
following bit of code. When I iterate round my hash before putting it in
the array of the hash values/keys are there. However, when I iterate
through the hash after putting it in the array
assign the reference of the hash.
--- Simon Tomlinson [EMAIL PROTECTED] wrote:
Hi
I want to put a hash into each element of an array.
I do it like the following bit of code. When I
iterate round my hash before putting it in the array
of the hash values/keys are there. However, when I
Does anyone have any clever ideas for sorting an array of hashes based on
a key such as an ID number?
Example:
@AoH = (
{ ID = 10101, UserID = 1041, Status = 2 },
{ ID = 10541, UserID = 1211, Status = 1 },
{ ID = 10111, UserID = 1211, Status = 2 },
{ ID = 10721
;
}
-Original Message-
From: Tomasi, Chuck [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, February 06, 2002 2:18 PM
To: '[EMAIL PROTECTED]'
Subject: Sorting an array of hashes
Does anyone have any clever ideas for sorting an array of hashes based on
a key such as an ID number
On Wed, 2002-02-06 at 14:17, Tomasi, Chuck wrote:
Does anyone have any clever ideas for sorting an array of hashes based on
a key such as an ID number?
Example:
@AoH = (
{ ID = 10101, UserID = 1041, Status = 2 },
{ ID = 10541, UserID = 1211, Status = 1 },
{ ID
- Original Message -
From: Tomasi, Chuck [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Wednesday, February 06, 2002 1:17 PM
Subject: Sorting an array of hashes
Does anyone have any clever ideas for sorting an array of hashes based on
a key such as an ID number?
Example:
@AoH
On Wed, 6 Feb 2002, Tomasi, Chuck wrote:
Does anyone have any clever ideas for sorting an array of hashes based on
a key such as an ID number?
Example:
@AoH = (
{ ID = 10101, UserID = 1041, Status = 2 },
{ ID = 10541, UserID = 1211, Status = 1 },
{ ID = 10111
:28 PM
To: 'Tomasi, Chuck'; '[EMAIL PROTECTED]'
Subject: RE: Sorting an array of hashes
@sorted = sort {
$a-{ID} = $b-{ID} ## remember that $a and $b
become the element
of the array
## so if it's a reference to a hash use a dereferencer '-' or
# $$a{ID} = $$b{ID
I have a systems hash that contains the type of system
as keys and the name of the machines as values:
%systems = (
sgi = [sgi1, sgi2],
linux = [linux1, linux2],
dec = [dec1, dec2]
};
Now, each type of system has default values like an
email help address, shell used, users home
1 - 100 of 116 matches
Mail list logo