Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re^2: can i concatenate various value to form a unique key

by Anonymous Monk
on Jul 03, 2009 at 10:15 UTC ( #777007=note: print w/replies, xml ) Need Help??

in reply to Re: can i concatenate various value to form a unique key
in thread can i concatenate various value to form a unique key

Hi, I am planning to have a hash like
%hash = {g1 => [start_date1,end_date2] g2 => [start_date1,end_date2] };
but i dont have a unique value of g1 and g2.. i will get unique value with combination of some values like value1 value2 value3 ..value5 so i planned to derive g with concatenation of these values assuming that a hash cannot have mutiple values of as a key. I thik the background is explained better now.

Replies are listed 'Best First'.
Re^3: can i concatenate various value to form a unique key
by Marshall (Abbot) on Jul 03, 2009 at 10:41 UTC
    At the risk of getting into more trouble in this thread, I do not think that this will work out well for you. There can be very good reasons to concatenate strings into a single hash key, but once we are talking about 5 FIVE dimensions, this doesn't make sense. I apologize for not reading this thread carefully from the beginning.

    sounds like you need an Array of Hash.

    each hash like: start => "some start date", end => "some end date", parm1 => "some data1", parm2 => "some data2", parm3 => "some data3",
Re^3: can i concatenate various value to form a unique key
by citromatik (Curate) on Jul 03, 2009 at 10:34 UTC

    Maybe I am wrong, but contrary to the others who have replied already, I think you are misinterpreting your problem (sorry if I misinterpreted you! :).

    Do you want the following:

    %hash = ( g1 => [value1, value2, value3], g2 => [value4, value5, value6...] );

    i.e. do you want each key to have multiple values associated? If this is the case you need a reference to an array containing all the values (see perlref). You already have that situation in the example you give: g1 => [$start_date1,$end_date1], so, to concatenate more values, you will need a reference to an AoA (array of arrays). Again, sorry if I totally misinterpreted your problem, but if you think I am close, let me know and we will elaborate it a little more


      i think i am bad in explaining :( my actaul issue with mutiple keys not values.. value i am laready refering to array. But to get that hash value array i need a key which is combination of various values. so i am stucked ....

        Like Marshall says, I think you want another data structure/strategy, you may get more helpful comments if you explain how did you run into this and give a wider view of your problem.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://777007]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2020-07-05 11:11 GMT
Find Nodes?
    Voting Booth?

    No recent polls found