Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • I came up with this to dump database tables to XML (using DBI and XML::Simple):
      my $xs = XML::Simple->new(rootname => 'record', suppressempty => undef);
    ...
      print qq!<TABLE name="$table">\n!;
      my $sth = $dbh->prepare("select * from $table");
      $sth->execute;
      my @row = map { { name => $_ } } @{ $sth->{NAME_lc} };
      my $record = { column => \@row };
      my @values = map { \$_->{content} } @row;
      $sth->bind_columns( @values );
      while ($sth->fetch) {
        defined $$_ or $$_ = '' for @values;
        print $xs->XMLout($record);
      }
      print "</TABLE>\n";
    It'll get even shorter (e.g. the 'defined' line will go away), if grantm [perl.org] ever releases the next version of XML::Simple [cpan.org] and remembers to include my patch :-)