Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Parse error

by naChoZ (Curate)
on Dec 18, 2007 at 14:34 UTC ( [id://657681]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://657681]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2024-04-20 03:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found