/[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

Diff of /bin/csv2yaml.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 9 by dpavlin, Sun Mar 15 19:45:44 2009 UTC revision 14 by dpavlin, Sun Mar 15 20:54:14 2009 UTC
# Line 37  foreach my $line ( split(/\r?\n/, $csv) Line 37  foreach my $line ( split(/\r?\n/, $csv)
37    
38          warn "# fields = ",dump( @fields ) if $debug;          warn "# fields = ",dump( @fields ) if $debug;
39    
40          $hash->{ $columns[$_] } = $fields[$_] foreach ( 0 .. $#fields );          foreach ( 0 .. $#fields ) {
41                    my $n = $columns[$_];
42                    my $v = $fields[$_];
43    
44                    $v =~ s{\s*#\s*$}{};
45                    $v =~ s{^\s+}{};
46                    $v =~ s{\s+$}{};
47    
48                    # fix tel fields
49                    $v =~ s{\s+}{#}g if $n =~ m{tel};
50    
51                    if ( $v =~ m{#} ) {
52                            my @v = split(/\s*#\s*/, $v);
53                            foreach my $pos ( 0 .. $#v ) {
54                                    if ( $n =~ m{tel} ) {
55                                            if ( $v[$pos] =~ m{^09} ) {
56                                                    $hash->{ $n . '_mobile' } ||= $v[$pos];
57                                            } else {
58                                                    $hash->{ $n . '_fixed' } ||= $v[$pos];
59                                            }
60                                    }
61                                    $hash->{ $n . '_' . $pos } = $v[$pos];
62                            }
63                    }
64                    $hash->{ $n } = $v;
65            }
66    
67          warn dump( $hash ) if $debug;          warn dump( $hash ) if $debug;
68    

Legend:
Removed from v.9  
changed lines
  Added in v.14

  ViewVC Help
Powered by ViewVC 1.1.26