File: read.write.tree.pl

package info (click to toggle)
libtree-dagnode-perl 1.35-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 388 kB
  • sloc: perl: 1,455; makefile: 2; sh: 1
file content (62 lines) | stat: -rwxr-xr-x 1,398 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env perl
#
# Name: read.write.tree.pl.
#
# Called by read.write.tree.sh.
#
# Reads a tree created by Tree::DAG_Node.tree2string()
# and somehow written to a disk file.

use 5.40.0;

use strict;
use warnings;
use warnings qw(FATAL utf8); # Fatalize encoding glitches.

use Data::Dumper; # For Dumper().

use File::Spec;

use Getopt::Long;

use Tree::DAG_Node;

# ------------------------------------------------

my(%options);

$options{dir_name}			= '';
$options{in_file_name}		= '';
$options{help}	 			= 0;
$options{log_level}			= 'info';
my(%opts)					=
(
	'dir_name=s'		=> \$options{dir_name},
	'in_file_name=s'	=> \$options{in_file_name},
	'help'				=> \$options{help},
	'log_level=s'		=> \$options{log_level},
);

GetOptions(%opts) || die("Error in options. Options: " . Dumper(%opts) );

if ($options{help} == 1)
{
	pod2usage(1);
}

my($input_file_name)	= File::Spec -> catfile($options{dir_name}, $options{in_file_name});
my($output_file_name)	= File::Spec -> catfile($options{dir_name}, $options{in_file_name} . '.new');

say "Reading: $input_file_name";

my($node)				= Tree::DAG_Node -> new;
my($root)				= $node -> read_tree($input_file_name);
my($no_attr)			= 0;

say "Writing: $output_file_name";

open(my $fh, '> :encoding(utf-8)', $output_file_name);
print $fh "$_\n" for @{$root -> tree2string({no_attributes => $no_attr})};
close $fh;

say "Wrote:   $output_file_name";