hash of hash of array slices

Ask a Question related to PERL Beginners, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. 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
    2. 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...
    3. 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 = {...
    4. 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......
    5. 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;
  3. #2

    Default 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

  4. #3

    Default 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.
    Hmmmm

    Paul Kraus Guest

  5. #4

    Default 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.

    --
    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

  6. #5

    Default 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

  7. #6

    Default 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

  8. #7

    Default 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

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139