dump undef or NULL values as \N
authorDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 23 Jun 2010 16:32:06 +0000 (18:32 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 23 Jun 2010 16:32:06 +0000 (18:32 +0200)
This is compatibile with PostgreSQL dump file format, and allows
us to correctly align columns for export to gnuplot

lib/MojoFacets/Data.pm

index ac7dc21..047886d 100644 (file)
@@ -748,11 +748,16 @@ sub items {
                foreach my $f ( 0 .. $#$filtered ) {
                        print $fh join("\t", map {
                                my $i = $data->{items}->[ $filtered->[$f] ];
-                               if ( ref $i->{$_} eq 'ARRAY' ) {
-                                       join(',', @{ $i->{$_} });
+                               my $v = '\N';
+                               if ( ! defined $i->{$_} ) {
+                                       # nop
+                               } elsif ( ref $i->{$_} eq 'ARRAY' ) {
+                                       $v =join(',', @{ $i->{$_} });
+                                       $v = '\N' if length($v) == 0;
                                } else {
-                                       dump $i->{$_};
+                                       $v = dump $i->{$_};
                                }
+                               $v;
                        } @columns),"\n";
                }
                close($fh);