/[virtual-ldap]/bin/csv2yaml.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /bin/csv2yaml.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9 - (hide annotations)
Sun Mar 15 19:45:44 2009 UTC (15 years, 1 month ago) by dpavlin
File MIME type: text/plain
File size: 808 byte(s)
convert CSV file to yaml
1 dpavlin 9 #!/usr/bin/perl
2    
3     use warnings;
4     use strict;
5    
6     # cvs2dbi.pl
7     #
8     # 03/15/2009 05:06:53 PM CET Dobrica Pavlinusic <dpavlin@rot13.org>
9    
10     use Data::Dump qw/dump/;
11     use File::Slurp;
12     use YAML qw/DumpFile/;
13     use Text::CSV;
14     use Encode qw/decode/;
15    
16     my $debug = 0;
17    
18     my $path = shift @ARGV || die "usage: $0 file.csv\n";
19    
20     my $csv = read_file( $path );
21     $csv = decode('utf-16', $csv);
22    
23     my @columns;
24    
25     foreach my $line ( split(/\r?\n/, $csv) ) {
26    
27     warn "## $line\n";
28    
29     my @fields = split(/;/, $line);
30     if ( ! @columns ) {
31     @columns = @fields;
32     warn "# columns = ",dump( @columns ) if $debug;
33     next;
34     }
35    
36     my $hash;
37    
38     warn "# fields = ",dump( @fields ) if $debug;
39    
40     $hash->{ $columns[$_] } = $fields[$_] foreach ( 0 .. $#fields );
41    
42     warn dump( $hash ) if $debug;
43    
44     my $uuid = $fields[0];
45    
46     DumpFile( "yaml/$uuid.yaml", $hash );
47     }

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26