Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
go ahead... be a heretic
 
PerlMonks  

Re: indefinite number of columns

by marto (Chancellor)
on Jul 15, 2013 at 13:35 UTC ( #1044377=note: print w/ replies, xml ) Need Help??


in reply to indefinite number of columns

Why not just parse each workbook of the spreadsheet using Spreadsheet::ParseExcel? The first example shows how to do this. Modifying this example to work on a per column basis (rather than by row) would be trivial.

Update: My mistake, you're working with a csv file.

book.csv:

1,2 ,3 1,2, 3 1,2,43 1 12,1 apple, 1, 3 orange 7,onion, 8, 9

Sample code using Text::CSV:

#!/usr/bin/perl use strict; use warnings; use Text::CSV; use Data::Dumper; my $csv = Text::CSV->new({ sep_char => ',' }); my $file = "book.csv"; open(my $csvdata, '<', $file) or die "Could not open '$file' $!\n"; while (my $line = <$csvdata>) { chomp $line; if ($csv->parse($line)) { my @fields = $csv->fields(); print Dumper \@fields; } }

What exactly are you trying to achieve?


Comment on Re: indefinite number of columns
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (15)
As of 2014-04-18 11:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (466 votes), past polls