Ask a Question related to PERL Beginners, Design and Development.
-
Paul Kraus #1
hash of hash of array slices
This works
Foreach ( @{$hash{$key1}{$key2}} )
This does note
Foreach ( @{($hash{$key1}{$key2})[9..1]} )
This gives me this error ....
Can't use undefined value as an array reference.
TIA,
Paul Kraus
-----------------------
PEL Supply Company
Network Administrator
-----------------------
800 321-1264 Toll Free
216 267-5775 Voice
216 267-6176 Fax
[url]www.pelsupply.com[/url]
-----------------------
Paul Kraus Guest
-
adding an array as a hash value
Hi Dermot. Dermot Paikkos wrote: And use warnings; These variables need to have better names so that it's more -
Need help on Hash Slices. !!
Hi, I have a list like @list = ( "key1: Vlan1 :0989\n" "key2: Vlan2 :0989\n" "key3: Vlan3 :0989\n" "key4: Vlan4 :0989\n"); I wanted to... -
Sort a hash based on values in the hash stored as arrays of hashes
Hmm. I'm not quite sure if I got the subject right, but I'll try to explain. :-) I've got a hash of elements stored like this: $VAR1 = {... -
Another reference question (hash of hash references)
beginners, I am trying to build a hash of hash references. My problem is that I need to be able to add a key/value pair to the internal hashes...... -
Using slices with 'my' to initialize hash keys and values.
I have the following piece of code which works (meaning, does what I expect): #!/usr/bin/perl use strict; use warnings; my %translation; -
Charles K. Clarkson #2
RE: hash of hash of array slices
Paul Kraus <pkraus@pelsupply.com> wrote:
:
: This works
:
: Foreach ( @{$hash{$key1}{$key2}} )
:
: This does note
:
: Foreach ( @{($hash{$key1}{$key2})[9..1]} )
:
: This gives me this error ....
: Can't use undefined value as an array reference.
:
foreach ( reverse @{ $hash{$key1}{$key2} }[ 1 .. 9 ] ) {
HTH,
Charles K. Clarkson
--
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328
Charles K. Clarkson Guest
-
Paul Kraus #3
RE: hash of hash of array slices
> Paul Kraus <pkraus@pelsupply.com> wrote:
That was a typo should have read [ 1..10]> :
> : This works
> :
> : Foreach ( @{$hash{$key1}{$key2}} )
> :
> : This does note
> :
> : Foreach ( @{($hash{$key1}{$key2})[9..1]} )
> :
> : This gives me this error ....
> : Can't use undefined value as an array reference.
> :
>
>
> foreach ( reverse @{ $hash{$key1}{$key2} }[ 1 .. 9 ] ) {
And the code doesn't work.
Hmmmm
Paul Kraus Guest
-
Jeff 'Japhy' Pinyan #4
Re: hash of hash of array slices
On Jan 26, Paul Kraus said:
It should be:>foreach ( @{($hash{$key1}{$key2})[9..1]} )
foreach ( @{ $hash{$key1}{$key2} }[1 .. 10] ) { ... }
based on your other email.
--
Jeff "japhy" Pinyan [email]japhy@pobox.com[/email] [url]http://www.pobox.com/~japhy/[/url]
RPI Acacia brother #734 [url]http://www.perlmonks.org/[/url] [url]http://www.cpan.org/[/url]
<stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
[ I'm looking for programming work. If you like my work, let me know. ]
Jeff 'Japhy' Pinyan Guest
-
Paul Kraus #5
RE: hash of hash of array slices
> -----Original Message-----
> From: Jeff 'japhy' Pinyan [mailto:japhy@perlmonk.org]
> Sent: Monday, January 26, 2004 12:10 PM
> To: Paul Kraus
> Cc: 'Perl Beginners'
> Subject: Re: hash of hash of array slices
>
> On Jan 26, Paul Kraus said:
>>> >foreach ( @{($hash{$key1}{$key2})[9..1]} )
> It should be:
>
> foreach ( @{ $hash{$key1}{$key2} }[1 .. 10] ) { ... }
>
> based on your other email.
This worked fine. However I was under the impression that any time you
worked with a slice that you had to surround the array in parenthesis.
When else does this not apply?
Paul Kraus Guest
-
Charles K. Clarkson #6
RE: hash of hash of array slices
: -----Original Message-----
: From: Paul Kraus [mailto:pkraus@pelsupply.com]
: Sent: Monday, January 26, 2004 10:52 AM
: To: 'Charles K. Clarkson'; 'Perl Beginners'
: Subject: RE: hash of hash of array slices
:
:
: > Paul Kraus <pkraus@pelsupply.com> wrote:
: > :
: > : This works
: > :
: > : Foreach ( @{$hash{$key1}{$key2}} )
: > :
: > : This does note
: > :
: > : Foreach ( @{($hash{$key1}{$key2})[9..1]} )
: > :
: > : This gives me this error ....
: > : Can't use undefined value as an array reference.
: > :
: >
: >
: > foreach ( reverse @{ $hash{$key1}{$key2} }[ 1 .. 9 ] ) {
: That was a typo should have read [ 1..10]
:
: And the code doesn't work.
Worked for me:
my( $key1, $key2 ) = qw| foo bar |;
my %hash;
$hash{$key1}{$key2} = [ 0 .. 20 ];
foreach ( reverse @{ $hash{$key1}{$key2} }[ 1 .. 9 ] ) {
print "$_\n";
}
Charles K. Clarkson
--
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328
Charles K. Clarkson Guest
-
Tim Johnson #7
RE: hash of hash of array slices
I think that only applies to a list slice, i.e. (split /\s+,$_)[3..9],
but an array slice doesn't need it, i.e. @array[2]
-----Original Message-----
From: Paul Kraus [mailto:pkraus@pelsupply.com]
Sent: Monday, January 26, 2004 9:38 AM
To: [email]japhy@pobox.com[/email]
Cc: 'Perl Beginners'
Subject: RE: hash of hash of array slices
This worked fine. However I was under the impression that any time you
worked with a slice that you had to surround the array in parenthesis.
When else does this not apply?
Tim Johnson Guest



Reply With Quote

