Yup, as I thought - the code is bogus. $table->cell (...) returns the contents of a single cell, not an array. But you already have all the table information in @totalrows. Consider:

use strict; use warnings; use HTML::TableExtract; my $te = HTML::TableExtract->new (); $te->parse (<<HTML); <table> <tr><td>Cell 1</td><td>Cell 2</td><td>Cell 3</td></tr> <tr><td>Cell 4</td><td>Cell 5</td><td>Cell 6</td></tr> </table> HTML my $table = $te->first_table_found; my @totalrows = $table->rows (); print "$_->[0] - $_->[1] - $_->[2]\n" for @totalrows;

Prints:

Cell 1 - Cell 2 - Cell 3 Cell 4 - Cell 5 - Cell 6

I've no idea what you are trying to achieve with the match and substitutions so I've left that stuff right out, but you can loop over the rows using for my $row (@totalrows) {...} where $row is a reference to the array of cells for the current row.

Maybe you could provide a similar sample with your problem data as the HTML data so we can see what you are trying to do?

Update: Changing the @totalrows assignment to:

my @totalrows = map {my $cells = $_; $_ ||= '***' for @{$cells}[0 .. 2]; $cells} $table->rows ();

sets "missing" cells to a default value ('***'). Running the updated code against the sample HTML generates:

Boss - Firstname Surname - *** Secretary - Name Surname, Mr Jones Smith - *** Medical Doctor - Bob Middlename Hope - *** Position 1 - Worker - Secretary *** - Asdf Ghjk - Name Lastname, First Last *** - Sally Mally - Joe Smoe, The Who, Will Timberland Position 2 - Paula Simon - Raymonde Maalouf

Perl reduces RSI - it saves typing

In reply to Re: Will a substitution in an if/else control structure default to $_? by GrandFather
in thread Will a substitution in an if/else control structure default to $_? by Lawliet

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.