calebcall has asked for the wisdom of the Perl Monks concerning the following question:
Hashes are a new realm for me, so I'm certain someone will be able to explain to me how simple this really is, but I've been trying and can't get it right. I have a string that I would like split in to a hash. I've been trying to use split, but maybe that's not the best way to do it. The string would look something like the following:
$info = "word1": 12345, "word2": true, "another_word": true, "something_else": ["Something", "Some 2", "http://www.website.com"], "more": "5"Of course, those are all made up values, but the point is, it's not always a word => number pairing, word => word, etc. It can be any combo and each keys element could be one value or multiple, comma separated values. What I would like to split the example up to would be:
"word1" => 12345, "word2" => true, "another_word" => true, "something_else" => ["Something", "Some 2", "http://www.website.com"], "more" => "5"
The split regex I was trying to use was '":\ ', so my code looked something like this:
%info = split (/(":\ )/, $info);That isn't working, any suggestions?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Trying to build a hash from a string...
by hdb (Monsignor) on Nov 09, 2013 at 09:18 UTC | |
by calebcall (Sexton) on Nov 09, 2013 at 09:33 UTC | |
|
Re: Trying to build a hash from a string...
by GrandFather (Saint) on Nov 09, 2013 at 09:02 UTC | |
|
Re: Trying to build a hash from a string...
by ww (Archbishop) on Nov 09, 2013 at 12:18 UTC | |
by AnomalousMonk (Archbishop) on Nov 09, 2013 at 17:12 UTC |