Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: split on comma-separated fields, where a field may have commas inside quotes

by toolic (Bishop)
on Jun 10, 2009 at 00:20 UTC ( [id://770148]=note: print w/replies, xml ) Need Help??


in reply to split on comma-separated fields, where a field may have commas inside quotes

Text::CSV_XS is useful:
use strict; use warnings; use Text::CSV_XS; use Data::Dumper; my $str = 'IBM,INTL BUSINESS MACHINES,"2,500",$108.14,$270350.00,$1625 +.00,0.60%,$126200.00, +$144150.00,+114.22%'; my $csv = Text::CSV_XS->new(); my $status = $csv->parse($str); my @columns = $csv->fields(); print Dumper(\@columns); __END__ $VAR1 = [ 'IBM', 'INTL BUSINESS MACHINES', '2,500', '$108.14', '$270350.00', '$1625.00', '0.60%', '$126200.00', ' +$144150.00', '+114.22%' ];
  • Comment on Re: split on comma-separated fields, where a field may have commas inside quotes
  • Download Code

Log In?
Username:
Password:

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

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

    No recent polls found