in reply to Will a substitution in an if/else control structure default to $_?
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Will a substitution in an if/else control structure default to $_?
by Lawliet (Curate) on Aug 21, 2008 at 05:51 UTC |