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