Oracleのテーブル定義をExcelシートに出力する(3)

#!/usr/bin/env perl

use XML::Simple;
use Tie::IxHash;
use Spreadsheet::WriteExcel;

*XML::Simple::new_hashref = 'new_hashref';
sub new_hashref {
  my $self = shift;
  tie my %hash, 'Tie::IxHash';
  %hash = @_;
  return \%hash;
}

if($ARGV[0] eq ""){
  die "usage: table_info_xml2xls.pl <filename.xls>"
}

$workbook = Spreadsheet::WriteExcel->new($ARGV[0]);

tie(%VAR, 'Tie::IxHash');
$VAR = XML::Simple->new()->XMLin('-');

foreach $table (keys %{$VAR->{table}}){
  $worksheet = $workbook->add_worksheet($table);
  $format = $workbook->add_format();
  $i = 0;
  foreach $row (@{$VAR->{table}->{$table}->{row}}){
    $j = 0;
    foreach $column (keys %{$row->{column}}){
      $worksheet->write_string($i, $j, $row->{column}->{$column}->{content}, $format);
      #print $row->{column}->{$column}->{content},"\n";
      $j++;
    }
    $i++;
  }
}

$workbook->close();

参照したページ
XML::Simple で RSS の entry を順番通りに取り出す方法
http://blog.dealforest.net/2009/09/xml-parse-in-order/
help to preserve the order of hash
http://www.perlmonks.org/?node_id=846121
知ってそうで意外と知られていないperlの小技 10選
http://d.hatena.ne.jp/download_takeshi/20100610/1276178221

$ ./ora_table_info.pl hr/hr@bros:1521/xe HR | ./table_info_xml2xls.pl table_info2.xls


実行結果
table_info2.xls 直