OGDL Perl API. Examples

Example 1. From a file to standard output

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;

Example 2. Getting a scalar from a file

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");

Example 3. Reading from a string

use Ogdl;
use Graph;

$g = Ogdl::stringToGraph($astring);

$s = $g->getScalar("groups[].a[2]");