File: convert

package info (click to toggle)
extrepo-data 1.0.6
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 10,544 kB
  • sloc: perl: 761; makefile: 5
file content (42 lines) | stat: -rwxr-xr-x 606 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/perl -w

use strict;
use warnings;

use TOML;
use YAML::XS qw/Load Dump/;

die "need two filenames!\n" unless defined($ARGV[1]);

my $from = $ARGV[0];
my $to = $ARGV[1];

my $unparsed;

open my $input, "<$from";
while(<$input>) {
	$unparsed .= $_;
}
close $input;

my $data;

if($from =~ /\.yaml$/) {
	$data = Load($unparsed);
} elsif ($from =~ /\.toml$/) {
	$data = from_toml($unparsed);
} else {
	...
}

if($to =~ /\.yaml$/) {
	$unparsed = Dump($data);
} elsif ($to =~ /\.toml$/) {
	$unparsed = to_toml($data);
} else {
	...
}

open my $output, ">$to";
print $output $unparsed;
close $output;