Changeset 12627
- Timestamp:
- 2006-08-31T13:46:50+12:00 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/perllib/plugins/CSVPlug.pm
r12610 r12627 108 108 # The first line contains the metadata element names 109 109 $$textref =~ s/^(.*?)\r?\n//; 110 my $csv_file_field_line = $1; 111 my @csv_file_fields = split(/\,/, $csv_file_field_line); 112 for (my $i = 0; $i < scalar(@csv_file_fields); $i++) { 113 # Remove any spaces from the field names 114 $csv_file_fields[$i] =~ s/ //g; 110 my @csv_file_fields = (); 111 my $csv_file_field_line = $1 . ","; # To make the regular expressions simpler 112 while ($csv_file_field_line ne "") { 113 # Handle quoted values 114 if ($csv_file_field_line =~ s/^\"(.*?)\"\,//) { 115 my $csv_file_field = $1; 116 $csv_file_field =~ s/ //g; # Remove any spaces from the field names 117 push(@csv_file_fields, $csv_file_field); 118 } 119 # Normal comma-separated case 120 elsif ($csv_file_field_line =~ s/^(.*?)\,//) { 121 my $csv_file_field = $1; 122 $csv_file_field =~ s/ //g; # Remove any spaces from the field names 123 push(@csv_file_fields, $csv_file_field); 124 } 125 # The line must be formatted incorrectly 126 else { 127 print STDERR "Error: Badly formatted CSV field line: $csv_file_field_line.\n"; 128 last; 129 } 115 130 } 116 131 $self->{'csv_file_fields'} = \@csv_file_fields;
Note:
See TracChangeset
for help on using the changeset viewer.