]> git.proxmox.com Git - pve-common.git/commit - src/PVE/SectionConfig.pm
improve parse_config in JSONSchema and SectionConfig
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 15 Jul 2015 08:09:41 +0000 (10:09 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 22 Jul 2015 06:15:54 +0000 (08:15 +0200)
commit3c4d612a70d9521345a54f520f183c8551ff3ad4
tree79400223feb4030a87b75b265dc8947ac057dfc8
parent8998d715de6bf45cc456a208130e03228c0a4549
improve parse_config in JSONSchema and SectionConfig

The old code used string substitution for every line of the
input string, while perl can also iterate over all matches
via the /g re modifier, and can turn ^ and $ to act as
beginning/end of line via the /m modifier.

Effectively allowing a "match over all lines" via a simple
while ($data =~ /^.*$/gm);

The situation is a little different in SectionConfig because
there's a nested loop invovled which doesn't work with /g.
For this there are two options and I chose the safer one by
simply doing a split on newlines first.
The alternative would be to open the data as a
filehandle-to-string and use <$fh> to read lines, however
I'd have to throw in an eval{} to be sure to close the
handle afterwards.
src/PVE/JSONSchema.pm
src/PVE/SectionConfig.pm