in reply to Re^7: Combinations of lists, etc
in thread Combinations of lists to a hash
"Do you need the hashes to different instances with same content?"
If I understand your question correctly, then yes. See example in update #2 of my original post. It's a hash of a hash and the inner hashes have the same keys and values (for a given line of input data).
After some more experimenting, since multiplying the right hand side (e.g. with 'x2') is not going to work (the reason for which still isn't clear to me), then what would be wrong with this kind of strategy: Multiply a string first then eval it:
At least it seems to do what's required. I know there's a trailing ',' in $val which could easily be removed, but doesn't seem to be causing a problem with the resulting hash.perl -MData::Dump -e '$val="(".("{(a,1),(b,2)},"x2).")";@hash{(key1,ke +y2)} = eval $val;dd $val;dd \%hash' "({(a,1),(b,2)},{(a,1),(b,2)},)" { key1 => { a => 1, b => 2 }, key2 => { a => 1, b => 2 } } # Or more concisely: perl -MData::Dump -e '@hash{(key1,key2)} = eval "(".("{(a,1),(b,2)},"x +2).")";dd \%hash'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^9: Combinations of lists, etc
by AnomalousMonk (Archbishop) on Oct 07, 2019 at 22:51 UTC | |
by tel2 (Pilgrim) on Oct 08, 2019 at 02:20 UTC | |
by AnomalousMonk (Archbishop) on Oct 08, 2019 at 03:42 UTC | |
by tel2 (Pilgrim) on Oct 08, 2019 at 04:44 UTC | |
|
Re^9: Combinations of lists, etc
by LanX (Saint) on Oct 07, 2019 at 21:55 UTC | |
by tel2 (Pilgrim) on Oct 07, 2019 at 22:23 UTC |