use Ogdl;
use Graph;
$g = Ogdl::fileToGraph("data.g");
# The next line can also be written as
# $g2 = $g->getGraph("groups[].a[2]");
# get and getGraph permform the same function
$g2 = $g->get("groups[].a[2]");
$g2->print;
Suppose a file config.g whose contents is:
hostname myMachine
network
eth0
ip 192.168.0.2
gw 192.168.0.1
mask 255.255.255.0
We can extract the IP field as a scalar as follows:
use Ogdl;
use Graph;
$g = Ogdl::fileToGraph("config.g");
$s = $g->getScalar("network.eth0.ip");
use Ogdl;
use Graph;
$g = Ogdl::stringToGraph($astring);
$s = $g->getScalar("groups[].a[2]");