Last active
July 19, 2018 02:05
-
-
Save moznion/4608205 to your computer and use it in GitHub Desktop.
Revisions
-
moznion revised this gist
Jan 23, 2013 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,7 +7,7 @@ use autodie; use XML::XML2JSON; sub get_json_contents { my ($json_filename) = @_; open my $fh, '<', $json_filename or die $!; @@ -47,5 +47,5 @@ sub write_xml_file { } my $json_filename = $ARGV[0]; my $xml_contents = convert2xml( get_json_contents($json_filename) ); write_xml_file( decide_xml_filename($json_filename), $xml_contents ); -
moznion created this gist
Jan 23, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,51 @@ #!/usr/bin/env perl use strict; use warnings; use utf8; use 5.012000; use autodie; use XML::XML2JSON; sub read_json_file { my ($json_filename) = @_; open my $fh, '<', $json_filename or die $!; my @json = split /\n/, do { local $/; <$fh> }; close $fh; return join '', @json; } sub convert2xml { my ($json) = @_; local $SIG{__WARN__} = sub { # Do nothing. }; # Suppress warning of XML::XML2JSON->new() my $xml2json = XML::XML2JSON->new( module => 'JSON::XS', pretty => 1, ); return $xml2json->json2xml($json); } sub decide_xml_filename { my ($json_filename) = @_; my @xml_filename = split /\./, $json_filename; $xml_filename[-1] = 'xml'; return join '.', @xml_filename; } sub write_xml_file { my ( $xml_filename, $xml ) = @_; open my $fw, '>', $xml_filename or die $!; print $fw $xml; close $fw; } my $json_filename = $ARGV[0]; my $xml = convert2xml( read_json_file($json_filename) ); write_xml_file( decide_xml_filename($json_filename), $xml );