annotate lib/csv.pm @ 1:4373f936111d draft

" master branch Updating with tag :CI_COMMIT_TAG - - Fxx"
author fgiacomoni
date Tue, 21 Jan 2020 16:09:45 -0500
parents 7c9269bded0e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
1 package csv ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
2
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
3 use strict;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
4 use warnings ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
5 use Exporter ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
6 use Carp ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
7
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
8 use Text::CSV ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
9
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
10 use Data::Dumper ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
11
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
12 use vars qw($VERSION @ISA @EXPORT %EXPORT_TAGS);
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
13
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
14 our $VERSION = "1.0";
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
15 our @ISA = qw(Exporter);
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
16 our @EXPORT = qw( get_csv_object get_value_from_csv_multi_header write_csv_from_hash);
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
17 our %EXPORT_TAGS = ( ALL => [qw( get_csv_object get_value_from_csv_multi_header write_csv_from_hash )] );
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
18
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
19 =head1 NAME
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
20
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
21 My::Module - An example module
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
22
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
23 =head1 SYNOPSIS
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
24
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
25 use My::Module;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
26 my $object = My::Module->new();
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
27 print $object->as_string;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
28
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
29 =head1 DESCRIPTION
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
30
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
31 This module does not really exist, it
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
32 was made for the sole purpose of
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
33 demonstrating how POD works.
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
34
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
35 =head1 METHODS
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
36
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
37 Methods are :
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
38
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
39 =head2 METHOD new
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
40
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
41 ## Description : new
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
42 ## Input : $self
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
43 ## Ouput : bless $self ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
44 ## Usage : new() ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
45
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
46 =cut
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
47
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
48 sub new {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
49 ## Variables
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
50 my $self={};
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
51 bless($self) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
52 return $self ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
53 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
54 ### END of SUB
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
55
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
56 =head2 METHOD get_csv_object
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
57
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
58 ## Description : builds a csv object and etablishes format
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
59 ## Input : $separator
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
60 ## Output : $csv
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
61 ## Usage : my ( $csv ) = get_csv_object( $separator ) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
62
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
63 =cut
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
64 ## START of SUB
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
65 sub get_csv_object {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
66 ## Retrieve Values
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
67 my $self = shift ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
68 my ( $separator ) = @_ ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
69
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
70 # my $csv = Text::CSV->new({'sep_char' => "$separator"});
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
71 my $csv = Text::CSV->new ( {'sep_char' => "$separator", binary => 1 } ) # should set binary attribute.
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
72 or die "Cannot use CSV: ".Text::CSV->error_diag ();
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
73
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
74 return($csv) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
75 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
76 ## END of SUB
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
77
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
78 =head2 METHOD get_value_from_csv_multi_header
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
79
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
80 ## Description : extract a targeted column in a csv file
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
81 ## Input : $csv, $file, $column, $is_header, $nb_header
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
82 ## Output : $value
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
83 ## Usage : my ( $value ) = get_value_from_csv_multi_header( $csv, $file, $column, $is_header, $nb_header ) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
84
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
85 =cut
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
86 ## START of SUB
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
87 sub get_value_from_csv_multi_header {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
88 ## Retrieve Values
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
89 my $self = shift ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
90 my ( $csv, $file, $column, $is_header, $nb_header ) = @_ ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
91
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
92 my @value = () ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
93
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
94 ## Adapte the number of the colunm : (nb of column to position in array)
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
95 $column = $column - 1 ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
96
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
97 open (CSV, "<", $file) or die $! ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
98
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
99 my $line = 0 ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
100
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
101 while (<CSV>) {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
102 $line++ ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
103 chomp $_ ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
104 # file has a header
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
105 if ( defined $is_header and $is_header eq 'yes') { if ($line <= $nb_header) { next ; } }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
106 # parsing the targeted column
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
107 if ( $csv->parse($_) ) {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
108 my @columns = $csv->fields();
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
109 push ( @value, $columns[$column] ) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
110 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
111 else {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
112 my $err = $csv->error_input;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
113 die "Failed to parse line: $err";
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
114 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
115 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
116 close CSV;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
117 return(\@value) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
118 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
119 ## END of SUB
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
120
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
121 =head2 METHOD parse_csv_object
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
122
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
123 ## Description : parse_all csv object and return a array of rows
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
124 ## Input : $csv, $file
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
125 ## Output : $csv_matrix
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
126 ## Usage : my ( $csv_matrix ) = parse_csv_object( $csv, $file ) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
127
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
128 =cut
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
129 ## START of SUB
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
130 sub parse_csv_object {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
131 ## Retrieve Values
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
132 my $self = shift ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
133 my ( $csv, $file ) = @_ ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
134
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
135 my @csv_matrix = () ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
136
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
137 open my $fh, "<:encoding(utf8)", $$file or die "Can't open csv file $$file: $!";
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
138
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
139 while ( my $row = $csv->getline( $fh ) ) {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
140 push @csv_matrix, $row;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
141 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
142 $csv->eof or $csv->error_diag();
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
143 close $fh;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
144
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
145 return(\@csv_matrix) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
146 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
147 ## END of SUB
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
148
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
149 =head2 METHOD parse_allcsv_object
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
150
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
151 ## Description : parse_all csv object and return a array of rows with or without header
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
152 ## Input : $csv, $file, $keep_header
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
153 ## Output : $csv_matrix
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
154 ## Usage : my ( $csv_matrix ) = parse_csv_object( $csv, $file, $keep_header ) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
155
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
156 =cut
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
157 ## START of SUB
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
158 sub parse_allcsv_object {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
159 ## Retrieve Values
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
160 my $self = shift ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
161 my ( $csv, $file, $keep_header ) = @_ ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
162
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
163 my @csv_matrix = () ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
164 my $line = 1 ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
165
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
166 open my $fh, "<:encoding(utf8)", $$file or die "Can't open csv file $$file: $!";
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
167
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
168 while ( my $row = $csv->getline( $fh ) ) {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
169 if ( ( $keep_header eq 'n' ) and ($line == 1) ) { }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
170 else { push @csv_matrix, $row; }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
171 $line ++ ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
172 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
173 my $status = $csv->eof or $csv->error_diag();
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
174 close $fh;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
175
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
176 return(\@csv_matrix, $status) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
177 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
178 ## END of SUB
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
179
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
180
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
181 =head2 METHOD write_csv_from_arrays
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
182
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
183 ## Description : write a csv file from list of rows
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
184 ## Input : $csv, $file_name, $rows
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
185 ## Output : $csv_file
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
186 ## Usage : my ( $csv_file ) = write_csv_from_arrays( $csv, $file_name, $rows ) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
187
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
188 =cut
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
189 ## START of SUB
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
190 sub write_csv_from_arrays {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
191 ## Retrieve Values
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
192 my $self = shift ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
193 my ( $csv, $file_name, $rows ) = @_ ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
194
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
195 my $fh = undef ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
196 $csv->eol ("\n"); ## end-of-line string to add to rows
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
197 # $csv->quote_char(undef) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
198 open $fh, ">:encoding(utf8)", "$file_name" or die "$file_name: $!";
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
199
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
200 my $status = $csv->print ($fh, $_) for @{$rows};
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
201 close $fh or die "$file_name: $!";
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
202
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
203 return(\$file_name) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
204 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
205 ## END of SUB
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
206
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
207 1 ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
208
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
209
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
210 __END__
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
211
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
212 =head1 SUPPORT
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
213
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
214 You can find documentation for this module with the perldoc command.
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
215
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
216 perldoc csv.pm
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
217
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
218 =head1 Exports
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
219
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
220 =over 4
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
221
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
222 =item :ALL is get_csv_object, get_value_from_csv_multi_header
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
223
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
224 =back
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
225
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
226 =head1 AUTHOR
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
227
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
228 Franck Giacomoni E<lt>franck.giacomoni@clermont.inra.frE<gt>
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
229
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
230 =head1 LICENSE
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
231
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
232 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
233
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
234 =head1 VERSION
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
235
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
236 version 1 : 23 / 10 / 2013
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
237
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
238 version 2 : ??
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
239
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
240 =cut