({ 1, 2, "three", 0, ({ "internal", "array", 0, }), "end", })
####
sub lpcarray_to_array
{
# Convert an lpc_array to a perl array
# Parameter: Object, LPCArray, Pointer to answer
my ($me, $larray, $ansp) = @_;
my @result = ();
print "lpcarray_to_array: $larray\n";
if($larray =~ /\({\s*(.*)/)
{
print "lpcarray_to_array: $1\n";
my @items = split(/,\s*/, $1);
while (@items)
{
$i = shift(@items);
if($i =~ /^\({(.*)/)
{
# Another array
my $passthrough = '';
unshift(@items, $1);
my $parsearray = '({' . join(', ', @items);
my @inarray = $me->lpcarray_to_array($parsearray,
\$passthrough);
if(defined($passthrough))
{
print "Got: $passthrough\n";
@items = split(/, \s*/, $passthrough);
}
$result[scalar(@result)] = \@inarray;
}
elsif($i =~/^\(\[(.*)/)
{
# A mapping
my $passthrough = '';
unshift(@items, $1);
my $parsehash = '([' . join(', ', @items);
my %inmapping = $me->lpcmapping_to_hash($parsehash,
\$passthrough);
if(defined($passthrough))
{
@items = split(/, \s*/, $passthrough);
}
$result[scalar(@result)] = \%inmapping;
}
elsif($i =~ /\"(.*)\"/)
{
# A string
$result[scalar(@result)] = $1;
}
elsif($i =~ /(\d+)/)
{
# A number
$result[scalar(@result)] = $1;
}
elsif($i =~ /\s*(.*)\s*}\)/)
{
# end of the array
$result[scalar(@result)] = $1;
${$ansp} = join(', ', @items);
return @result;
}
else
{
# Something we don't recognise
# Muss belong to the other parser
print "Don't know $i in lpcarray\n";
${$ansp} = $i . ', ' . join(', ', @items);
}
}
}
${$ansp} = undef;
return @result;
}
##
##
([ "key1": "value", "key2": ({ "value", "array", }) ])