| 1 |
#!/usr/bin/perl -w |
| 2 |
|
| 3 |
############################################################################# |
| 4 |
# This example is a bit outdated, please use the new bin/graph-easy script - |
| 5 |
# which is after "make install" available on any command line in your system. |
| 6 |
|
| 7 |
# Convert an input file containing a Graph::Easy object, then dump |
| 8 |
# it again as textual description. |
| 9 |
|
| 10 |
# Example usage: |
| 11 |
# examples/as_txt t/in/2nodes.txt |
| 12 |
# echo "[ A ] -> [ B ]" | examples/as_txt |
| 13 |
|
| 14 |
BEGIN { $|++; } |
| 15 |
|
| 16 |
use lib 'lib'; |
| 17 |
use Graph::Easy::Parser; |
| 18 |
|
| 19 |
my $file = shift; |
| 20 |
my $id = shift || ''; |
| 21 |
my $debug = shift; |
| 22 |
|
| 23 |
my $parser = Graph::Easy::Parser->new( debug => $debug ); |
| 24 |
|
| 25 |
if (!defined $file) |
| 26 |
{ |
| 27 |
$file = \*STDIN; |
| 28 |
binmode STDIN, ':utf8' or die ("binmode STDIN, ':utf8' failed: $!"); |
| 29 |
} |
| 30 |
my $graph = $parser->from_file( $file ); |
| 31 |
|
| 32 |
die ($parser->error()) unless defined $graph; |
| 33 |
|
| 34 |
$graph->id($id); |
| 35 |
|
| 36 |
warn($graph->error()) if $graph->error(); |
| 37 |
binmode STDOUT, ':utf8' or die ("binmode STDOUT, ':utf8' failed: $!"); |
| 38 |
print $graph->as_txt(); |
| 39 |
|