I’m trying to read in a multi-line config file with records into a perl hash array
Example Config File:
record_1
phone=5551212
data=1234234
end_record_1
record_2
people_1=bob
people_2=jim
data=1234
end_record_2
record_3
people_1=sue
end_record_3
here’s what I’m looking for:
$myData{1}{"phone"} <--- 5551212
$myData{1}{"data"} <--- 1234234
$myData{2}{"people_1"} <--- bob
... etc
What’s the best way to read this in? Module? Regex with multi-line match? Brute force? I’m up in the air on where to head next.
Here’s one option with your data set:
Output:
Setting
local $/ = ''results in an empty line being treated as a “record separator” in your data set, so we can use regexs on those records to grab the information for the hash keys/values.Hope this helps!