in reply to Re: hash array question
in thread hash array question

Many thanks, this is what i'm looking for. Is it also possible to add a key to each sub array? Something like:
RED => [ {KEYNAME =>[ PRICE => 0, CODE => 'code value 1', LABEL => 'RED'] }, { KEYNAME => [PRICE => 0, CODE => 'code value 2', LABEL => 'RED',}] ], BLUE => [KEYNAME => [ { PRICE => 1, CODE => 'code value 3', LABEL => 'BLUE', } ]]

Replies are listed 'Best First'.
Re^3: hash array question
by AnomalousMonk (Archbishop) on Nov 11, 2019 at 22:21 UTC

    Also, an expression such as
        { KEYNAME => [ PRICE => 0, CODE => 'code value 1', LABEL => 'RED' ] }
    suggests you may be mistaking an array element for part of a hash key/value pair. The  => (fat arrow) operator is just a fancy comma (see Comma Operator), it does nothing | nothing in and of itself to form key/value pairs. The expression above is equivalent to
        { KEYNAME => [ 'PRICE', 0, 'CODE', 'code value 1', 'LABEL', 'RED' ] }
    (update: in which an anonymous array is initialized with a set of unrelated, i.e., unpaired, elements).


    Give a man a fish:  <%-{-{-{-<

Re^3: hash array question
by choroba (Cardinal) on Nov 11, 2019 at 16:28 UTC
    Sorry, I don't understand. After RED, you have two hashes in an array, but after BLUE, there's no hash, just an array. Also, are you sure you want to store the tuples in an array instead of a hash?

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]