L
leeg
I have an input file of a format that looks something like this:
{
foo = (
{
bar = "baz";
wibble = WOBBLE;
},
{
bar = "barney";
wibble = JELLY;
}
);
someKey = someValue;
someArray = (value1, value2);
blankDict = {};
};
I've noticed (and at the time was fairly proud of said epiphany) that
this is almost a declaration of an anonymous hash and with a little
tweaking I could eval it as such. However, I need to quote it properly,
and despite a number of attempts can't construct a regex that will do it.
I want to search for a list of characters which are not the various
formatting characters [^\(\){};,=] *and* are not already surrounded by
quotes, and then surround them by quotes.
I thought of:
$line =~ s/[\s\(\){};,=]+([^"\(\){};,=])+[\s\(\){};,=]+/"$1"/g;
but this converts the above into:
{
foo" "
{
bar = "baz";
wibble"E"
},
{
bar = "barney";
wibble"Y"
}
);
someKey"e"
someArray"1"value2);
blankDict" "
}
so isn't what I want. What I especially can't determine is why " =
someValue;" for instance would be replaced by "e". Could someone offer
some assistance?
Ta,
leeg.
{
foo = (
{
bar = "baz";
wibble = WOBBLE;
},
{
bar = "barney";
wibble = JELLY;
}
);
someKey = someValue;
someArray = (value1, value2);
blankDict = {};
};
I've noticed (and at the time was fairly proud of said epiphany) that
this is almost a declaration of an anonymous hash and with a little
tweaking I could eval it as such. However, I need to quote it properly,
and despite a number of attempts can't construct a regex that will do it.
I want to search for a list of characters which are not the various
formatting characters [^\(\){};,=] *and* are not already surrounded by
quotes, and then surround them by quotes.
I thought of:
$line =~ s/[\s\(\){};,=]+([^"\(\){};,=])+[\s\(\){};,=]+/"$1"/g;
but this converts the above into:
{
foo" "
{
bar = "baz";
wibble"E"
},
{
bar = "barney";
wibble"Y"
}
);
someKey"e"
someArray"1"value2);
blankDict" "
}
so isn't what I want. What I especially can't determine is why " =
someValue;" for instance would be replaced by "e". Could someone offer
some assistance?
Ta,
leeg.