hi ben --
In a message dated 1/10/2007 10:35:00 A.M. Eastern Standard Time,
[EMAIL PROTECTED] writes:
> I am making a PDF , which using PDF::Table I am making a table inside that
PDF.
>
> What I am trying to do is make the table dynamic, cause I am passing
variables
> and I do not want a blank table row if the variable is empty. This is what
I
> have tried so far:
>
> my $some_data =[
> ["HP Hardware", "Total Cost"],
> [$hardware1, $hardwareValue1],
> [$hardware2, $hardwareValue2],
> [$hardware3, $hardwareValue3],
> [$hardware4, $hardwareValue4],
> [$hardware5, $hardwareValue5],
> [$hardware6, $hardwareValue6],
> [$hardware7, $hardwareValue7],
> [$hardware8, $hardwareValue8],
> [$hardware9, $hardwareValue9],
> [$hardware10, $hardwareValue10],
> [$hardware11, $hardwareValue11],
> [$hardware12, $hardwareValue12],
> [$hardware13, $hardwareValue13],
> [$hardware14, $hardwareValue14],
> [$hardware15, $hardwareValue15],
> ];
>
> for (my $i=0; $i< scalar($some_data); $i++) {
>
> if ($hardware[$i] eq "") {
>
> }
>
> }
>
> I am thinking if the variable is blank I want to delete the row from
> $some_data, I don’t know the syntax to do it,
>
> Any help or suggestions would be helpful, thanks
>
> Ben
for detailed answers to your questions (and many others that are implied), i
strongly recommend
you review the following documentation and tutorials:
perlref
perlreftut
perllol
perldsc
a quick and dirty (and UNTESTED) answer to your specific question about how
to remove
non-significant items from a referenced array is as follows:
ROW:
for (my $i = 0; $i < @$some_data; ++$i) {
if ($some_data->[$i][0] eq '') {
splice @$some_data, $i, 1;
redo ROW;
}
}
however, a different approach might be more effective: only take some action
(e.g., inserting
a row into a pdf table) if the row data is significant. for instance (also
UNTESTED):
for (my $i = 0; $i < @$some_data; ++$i) {
if ($some_data->[$i][0]) { # if row data significant...
insert_in_my_pdf_table(@{ $some_data->[$i] }); # pass items of
de-referenced sub-array
}
}
also - take a look at hashes of hashes for implementing this kind of data
table (discussion and
examples in perldsc - perl data structures cookbook).
also - always use warnings; and use strict;
hth -- bill walters
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs