Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

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

by citromatik (Curate)
on Jul 03, 2009 at 07:50 UTC ( #776974=note: print w/ replies, xml ) Need Help??


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

I don't know exactly what you are trying to address (sounds like an XY Problem to me). You can use any string as a key in a hash, as long as it is unique in the hash, but building a hash whose keys are the concatenated values of other keys sounds like a design problem to me, maybe other data structures should be used instead

Could you please give a step backwards and elaborate a bit more the kind of problem you are trying to solve and why do you think that such a hash is a good option?

citromatik


Comment on Re: can i concatenate various value to form a unique key
Re^2: can i concatenate various value to form a unique key
by Anonymous Monk on Jul 03, 2009 at 10:15 UTC
    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.

      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

      citromatik

        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 ....
      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",

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2014-08-21 15:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (136 votes), past polls