Changeset 13174
- Timestamp:
- 2006-10-27T14:33:59+13:00 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/perllib/plugins/MetadataCSVPlug.pm
r13173 r13174 108 108 my $csv_file_field_line = shift(@csv_file_lines); 109 109 my @csv_file_fields = split(/\,/, $csv_file_field_line); 110 my $found_filename_field = 0; 110 111 for (my $i = 0; $i < scalar(@csv_file_fields); $i++) { 111 112 # Remove any spaces from the field names 112 113 $csv_file_fields[$i] =~ s/ //g; 114 if ($csv_file_fields[$i] eq "Filename") { 115 $found_filename_field = 1; 116 } 113 117 } 114 118 119 if (!$found_filename_field) { 120 print STDERR "MetadataCSVPlug Error: No Filename field in CSV file: $filename\n"; 121 return -1; # error 122 } 115 123 # Read each line of the file and assign the metadata appropriately 116 124 foreach my $csv_line (@csv_file_lines) { 117 125 # Ignore lines containing only whitespace 118 126 next if ($csv_line =~ /^\s*$/); 119 127 my $orig_csv_line = $csv_line; 120 128 # Build a hash of metadata name to metadata value for this line 121 129 my %csv_line_metadata; … … 127 135 # Only bother with non-empty values 128 136 if ($1 ne "" && defined($csv_file_fields[$i])) { 129 $csv_line_metadata{$csv_file_fields[$i]} = $1; 137 if (!defined $csv_line_metadata{$csv_file_fields[$i]}) { 138 $csv_line_metadata{$csv_file_fields[$i]} = []; 139 } 140 push (@{$csv_line_metadata{$csv_file_fields[$i]}}, $1); 130 141 } 131 142 } … … 134 145 # Only bother with non-empty values 135 146 if ($1 ne "" && defined($csv_file_fields[$i])) { 136 $csv_line_metadata{$csv_file_fields[$i]} = $1; 147 if (!defined $csv_line_metadata{$csv_file_fields[$i]}) { 148 $csv_line_metadata{$csv_file_fields[$i]} = []; 149 } 150 push (@{$csv_line_metadata{$csv_file_fields[$i]}}, $1); 137 151 } 138 152 } 139 153 # The line must be formatted incorrectly 140 154 else { 141 print STDERR " Error: Badly formatted CSV line: $csv_line.\n";155 print STDERR "MetadataCSVPlug Error: Badly formatted CSV line: $csv_line.\n"; 142 156 last; 143 157 } … … 147 161 148 162 # We can't associate any metadata without knowing the file to associate it with 149 my $csv_line_filename = $csv_line_metadata{"Filename"};150 if (!defined ($csv_line_filename)) {151 print STDERR " Error: No Filename metadata in CSV line: $csv_line\n";163 my $csv_line_filename_array = $csv_line_metadata{"Filename"}; 164 if (!defined $csv_line_filename_array) { 165 print STDERR "MetadataCSVPlug Error: No Filename metadata in CSV line: $orig_csv_line\n"; 152 166 next; 153 167 } 168 my $csv_line_filename = shift(@$csv_line_filename_array); 154 169 delete $csv_line_metadata{"Filename"}; 155 170
Note:
See TracChangeset
for help on using the changeset viewer.