http://qs321.pair.com?node_id=657681


in reply to Parse error

I'm sure Tie::CSV_file is a fine module, but you might also give Parse::CSV a spin. Here's some cutting and pasting of some code I wrote recently.

use Parse::CSV; # Define the names of our csv fields # my $csv_fields = [ 'CoordinatorID', 'CompanyName', 'FirstName', 'LastName', 'City', 'State', 'csgaccount', 'Username', 'DomainName' ]; # Populate these hashrefs with data for comparison with the # list of names. # my $provisioned = fetch_csv_accounts({ filename => $opts->{prov}, fields => $csv_fields }); # {{{ sub fetch_csv_accounts # sub fetch_csv_accounts { my $args = shift; die "No field names provided...\n" unless defined $args->{fields}; die "No filename provided...\n" unless defined $args->{filename +}; # Default the keyfield to Username if nothing # is passed to this sub. # my $keyfield = $args->{keyfield} ? $args->{keyfield} : 'Username'; # # Create a Parse::CSV object for easy csv iteration # my $prov_csv = Parse::CSV->new( file => $args->{filename}, fields => $args->{fields}, ); die "Error: " . $prov_csv->errstr . "\n" if $prov_csv->errstr; # Loop through each row of the csv file and populate the # hashref. The resulting hashref will look like: # # Username1 -> CoordinatorID # -> CompanyName # -> FirstName # -> Lastname # -> City # -> State # -> csgaccount # -> Username # -> DomainName # Username2 -> CoordinatorID # -> CompanyName # ... etc ... my $return_hash = {}; while ( my $row = $prov_csv->fetch ) { foreach ( keys %{$row} ) { $return_hash->{ $row->{$keyfield} }->{$_} = $row->{$_}; } } return $return_hash; } # }}}

--
naChoZ

Therapy is expensive. Popping bubble wrap is cheap. You choose.