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?
In reply to Trying to build a hash from a string... by calebcall
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |