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
I have solved the problem, I would be interested in any comments however on
this script. Positive and negative comments are welcome.
#!/usr/bin/perl
use strict;
use warnings;
my @vggroup;
my @PV;
my $PV=0;
my $Extents;
my $AllocatedPE;
my $rec = {};
my $href;
my $extent;
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
[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
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,
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]
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.
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
you have a space that shouldn't be there:
print THIS DOESN'T WORK: $key $newHash {$key}\n;
^
should be:
print THIS DOESN'T WORK: $key $newHash{$key}\n;
-Original Message-
From: Simon Tomlinson [mailto:[EMAIL
: 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
S I have a systems hash that contains the type of system
S as keys and the name of the machines as values:
S %systems = (
Ssgi = [sgi1, sgi2],
Slinux = [linux1, linux2],
Sdec = [dec1, dec2]
S };
S Now, each type of system has default values like an
S email help address, shell
Daniel,
I am recreating the systems password, group and shadow
(when applicable) files.
So if the script is run on an sgi system, for example,
the files location is /etc. If it is run on a linux
machine is /usr/local/system. If there are new users,
create new directories for them: for sgis on
So in the example that Daniel shows, how would I get
(reference) the value for the shell path for the sgi
system?
--- Daniel Gardner [EMAIL PROTECTED] wrote:
S I have a systems hash that contains the type of
system
S as keys and the name of the machines as values:
S %systems = (
Ssgi
On Oct 31, Sofia said:
So in the example that Daniel shows, how would I get
(reference) the value for the shell path for the sgi
system?
Using the data structure:
%systems = (
sgi = { defaults =
[sgi-help,/bin/csh,/home],
machines = [sgi1, sgi2],
},
On Wed, Oct 31, 2001 at 09:53:58AM -0800, Sofia wrote:
[snip]
%systems = (
sgi = [sgi1, sgi2],
linux = [linux1, linux2],
dec = [dec1, dec2]
};
[snip]
%default = (
sgi = [sgi-help,/bin/csh,/home],
linux =
[someaddress-help,/bin/bash,/usr/home],
dec =
Jonathan Batchelor writes:
I have a data structure similar to the following:
@hosts = ( list of hashes like below ... );
%hosts = ( name = hostname,
ipaddr = www.xxx.yyy.zzz,
location = location
);
How can produce a sorted list of the hashes based on the
On Sep 24, Pete Sergeant said:
@hosts = sort { %{$a}-{'name'} = %{$b}-{'name'} } @hosts;
That (%{$x}-{key}) works for an ugly reason. It's probably a bug.
@hosts = sort { $a-{name} cmp $b-{name} } @hosts;
--
Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
RPI
28 matches
Mail list logo