No such thing as a small change | |
PerlMonks |
Using a regex to replace looping and splittingby mwb613 (Beadle) |
on Jan 24, 2018 at 00:08 UTC ( [id://1207789]=perlquestion: print w/replies, xml ) | Need Help?? |
mwb613 has asked for the wisdom of the Perl Monks concerning the following question: Thanks in advance for looking! I have a string returned from a DB (Redis) that is pipe delimited and the individual items that are delimited are colon delimited ex: special:1001:area_code:617|special:1001:zip_code:02205|special:1001:dow:0|special:1001:tod:14My goal is to convert these into a hash that looks like this (the first few sub-fields can be ignored):
I could write a loop no problem:
that uses two splits though and I'm thinking a grep would be more efficient. Is there a way to iteratively progress through a string with a regex and use the matches to fill a hash? The below could work but it wouldn't account for the "big string" having a variable number of delimited members
Would a Map work here? I'm inexperienced with it but my thought is that it will only apply if we do a split on the initial string
Back to
Seekers of Perl Wisdom
|
|