/[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 11 by dpavlin, Sun Mar 15 20:01:21 2009 UTC revision 21 by dpavlin, Mon Mar 16 10:02:46 2009 UTC
# Line 42  foreach my $line ( split(/\r?\n/, $csv) Line 42  foreach my $line ( split(/\r?\n/, $csv)
42                  my $v = $fields[$_];                  my $v = $fields[$_];
43    
44                  $v =~ s{\s*#\s*$}{};                  $v =~ s{\s*#\s*$}{};
45                    $v =~ s{^\s+}{};
46                    $v =~ s{\s+$}{};
47    
48                  if ( $v =~ m{#} ) {                  # fix tel fields
49                          my @v = split(/\s*#\s*/, $v);                  $v =~ s{\s+}{#}g if $n =~ m{tel};
50                    $v =~ s[\x{17d}][F] if $n =~ m{spol};
51    
52                    if ( $v =~ m{#} ) { # subfields delimiter in CSV data
53                            my @v = split(/\s*#+\s*/, $v);
54                          foreach my $pos ( 0 .. $#v ) {                          foreach my $pos ( 0 .. $#v ) {
55                                    if ( $n =~ m{tel} ) {
56                                            if ( $v[$pos] =~ m{^09} ) {
57                                                    $hash->{ $n . '_mobile' } ||= $v[$pos];
58                                            } else {
59                                                    $hash->{ $n . '_fixed' } ||= $v[$pos];
60                                            }
61                                    }
62                                  $hash->{ $n . '_' . $pos } = $v[$pos];                                  $hash->{ $n . '_' . $pos } = $v[$pos];
63                          }                          }
64    
65                            $hash->{ $n } = [ @v ];
66                    } else {
67                            $hash->{ $n } = $v;
68                  }                  }
                 $hash->{ $n } = $v;  
69          }          }
70    
71          warn dump( $hash ) if $debug;          warn dump( $hash ) if $debug;

Legend:
Removed from v.11  
changed lines
  Added in v.21

  ViewVC Help
Powered by ViewVC 1.1.26