Assuming (a) the modification proposed by Eliya, and (b) that you placed correctly a comma at the correct places, you end up with a string $s containing the whole content of the file, modified like this:
If you manage to come so far, you can easily get a reference to this hash with" KEY1 => 'VALUE1', \n KEY2 => [ 'VALUE21',\n 'VALUE22'\n'VALUE23' + ]"
So perhaps the most tricky part is to get the commas in the right place. To do this, I would first place a comma in front of every /\b(\S+?\s*=>)/, which leaves us one extra comma near the start of the string, which you have to remove afterwards. Well, maybe there is also a simpler solution to this. However, in any case you would make your life easier by forbidding input data similar tomy $hashref=eval "{${s}}"; if($@) { print STDERR "Error in input: $@\n"; } else { # Dump the data just read print("Key $_ has value ",$hashref->{$_},"\n") for keys %$s; }
KEY1 => 'abc THIS_LOOKS_LIKE_A_KEY_BUT_IS_NOT => \'uh-oh\' this might +cause trouble' KEY2 => '.....'
In reply to Re^3: Initialize an hash with string
by rovf
in thread Initialize an hash with string
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |