Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: indefinite number of columns

by marto (Bishop)
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.


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?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1044377]
[jedikaiti]: Happy Monday
[Tanktalus]: What's so happy about it? :P
[Tanktalus]: ww: your parens don't line up. Sure, perl can look like line noise, but the parens still have to line up. ;)
[Tux]: 1nickt did you build 5.24.3, 5.26.1, and 5.27.4 yet?

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2017-09-25 16:32 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (282 votes). Check out past polls.