Why would you overcomplicate this? Use Spreadsheet::Read (or Spreadsheet::ParseXLSX directly) to read your Excel sheet and then use Text::CSV_XS (or Text::CSV) on the content of the cell(s) you want to split

Here is a tested example. The pm1226189.xlsx that I used has comma-separated fields that also include newlines and quotation. If your Excel also contains encoded fields, you probably have to deal with that inside the inner loop

#!/pro/bin/perl use 5.14.1; use warnings; use Data::Peek; use Spreadsheet::Read; use Text::CSV_XS; my $book = Spreadsheet::Read->new ("pm1226189.xlsx") or die "Cannot read spreadsheet: $!\n"; my $sheet = $book->sheet (1) or die "Book has no sheets\n"; my $csv = Text::CSV_XS->new ({ binary => 1, auto_diag => 1, allow_whitespace => 1, }); my @data; foreach my $col (1 .. $sheet->maxcol) { foreach my $row (1 .. $sheet->maxrow) { my $cell = $sheet->cell ($col, $row); if ($cell && $cell =~ m/,/) { open my $fh, "<", \$cell; $data[$col][$row] = $csv->getline ($fh); close $fh; } else { $data[$col][$row] = $cell; } } } DDumper \@data;

Enjoy, Have FUN! H.Merijn

In reply to Re: splinting a line of text by comma by Tux
in thread splinting a line of text by comma by benaw

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.