Creating a Dynamic Table??

Creating a Dynamic Table??

am 10.01.2007 16:32:08 von Ben Eagle

This is a multi-part message in MIME format.

--===============1709404664==
Content-Class: urn:content-classes:message
Content-Type: multipart/alternative;
boundary="----_=_NextPart_001_01C734CC.7D20D568"

This is a multi-part message in MIME format.

------_=_NextPart_001_01C734CC.7D20D568
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

I am making a PDF , which using PDF::Table I am making a table inside
that PDF.

=20

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:

=20

my $some_data =3D[

["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],

];

=20

for (my $i=3D0; $i< scalar($some_data); $i++) {

=20

if ($hardware[$i] eq "") {

=20

}

=20

}

=20

=20

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,

=20

Any help or suggestions would be helpful, thanks

=20

Ben


------_=_NextPart_001_01C734CC.7D20D568
Content-Type: text/html;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable




charset=3Dus-ascii">












style=3D'font-size:10.0pt;
font-family:Arial'>I am making a PDF , which using PDF::Table I am =
making a
table inside that PDF.



style=3D'font-size:10.0pt;
font-family:Arial'> 



style=3D'font-size:10.0pt;
font-family:Arial'>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:



style=3D'font-size:10.0pt;
font-family:Arial'> 



style=3D'font-size:10.0pt;
font-family:Arial'>my $some_data =3D[



style=3D'font-size:10.0pt;
font-family:Arial'>    ["HP Hardware", =
"Total
Cost"],



style=3D'font-size:10.0pt;
font-family:Arial'>    [$hardware1, =
$hardwareValue1],



style=3D'font-size:10.0pt;
font-family:Arial'>         =
   [$hardware2,
$hardwareValue2],



style=3D'font-size:10.0pt;
font-family:Arial'>         =
   [$hardware3,
$hardwareValue3],



style=3D'font-size:10.0pt;
font-family:Arial'>         =
   [$hardware4,
$hardwareValue4],



style=3D'font-size:10.0pt;
font-family:Arial'>         =
   [$hardware5,
$hardwareValue5],



style=3D'font-size:10.0pt;
font-family:Arial'>         =
   [$hardware6,
$hardwareValue6],



style=3D'font-size:10.0pt;
font-family:Arial'>         =
   [$hardware7,
$hardwareValue7],



style=3D'font-size:10.0pt;
font-family:Arial'>         =
   [$hardware8,
$hardwareValue8],



style=3D'font-size:10.0pt;
font-family:Arial'>         =
   [$hardware9,
$hardwareValue9],



style=3D'font-size:10.0pt;
font-family:Arial'>         =
   [$hardware10,
$hardwareValue10],



style=3D'font-size:10.0pt;
font-family:Arial'>         =
   [$hardware11,
$hardwareValue11],



style=3D'font-size:10.0pt;
font-family:Arial'>         =
   [$hardware12,
$hardwareValue12],



style=3D'font-size:10.0pt;
font-family:Arial'>         =
   [$hardware13,
$hardwareValue13],



style=3D'font-size:10.0pt;
font-family:Arial'>         =
   [$hardware14,
$hardwareValue14],



style=3D'font-size:10.0pt;
font-family:Arial'>         =
   [$hardware15,
$hardwareValue15],



style=3D'font-size:10.0pt;
font-family:Arial'> ];



style=3D'font-size:10.0pt;
font-family:Arial'> 



style=3D'font-size:10.0pt;
font-family:Arial'>for (my $i=3D0; $i< scalar($some_data); $i++) =
{



style=3D'font-size:10.0pt;
font-family:Arial'> 



style=3D'font-size:10.0pt;
font-family:Arial'>         =
   if
($hardware[$i] eq "") {



style=3D'font-size:10.0pt;
font-family:Arial'>         =
            &=
nbsp; 



style=3D'font-size:10.0pt;
font-family:Arial'>         =
   }



style=3D'font-size:10.0pt;
font-family:Arial'> 



style=3D'font-size:10.0pt;
font-family:Arial'>}



style=3D'font-size:10.0pt;
font-family:Arial'> 



style=3D'font-size:10.0pt;
font-family:Arial'> 



style=3D'font-size:10.0pt;
font-family:Arial'>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,



style=3D'font-size:10.0pt;
font-family:Arial'> 



style=3D'font-size:10.0pt;
font-family:Arial'>Any help or suggestions would be helpful, =
thanks



style=3D'font-size:10.0pt;
font-family:Arial'> 



style=3D'font-size:10.0pt;
font-family:Arial'>Ben









------_=_NextPart_001_01C734CC.7D20D568--

--===============1709404664==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============1709404664==--

Re: Creating a Dynamic Table??

am 10.01.2007 21:15:09 von Williamawalters

--===============1918579394==
Content-Type: multipart/alternative;
boundary="-----------------------------1168460109"


-------------------------------1168460109
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Content-Language: en

=20
hi ben -- =20
=20
In a message dated 1/10/2007 10:35:00 A.M. Eastern Standard Time, =20
beagle@alinean.com writes:
=20
> I am making a PDF , which using PDF::Table I am making a table inside tha=
t=20
PDF.
>=20
> What I am trying to do is make the table dynamic, cause I am passing=20
variables
> and I do not want a blank table row if the variable is empty. This is wha=
t=20
I
> have tried so far:
>=20
> my $some_data =3D[
> ["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],
> ];
> =20
> for (my $i=3D0; $i< scalar($some_data); $i++) {
> =20
> if ($hardware[$i] eq "") {
> =20
> }
>=20
> }
>=20
> I am thinking if the variable is blank I want to delete the row from
> $some_data, I donâ€=99t know the syntax to do it,
>=20
> Any help or suggestions would be helpful, thanks
> =20
> Ben


for detailed answers to your questions (and many others that are implied), =20=
i=20
strongly recommend=20
you review the following documentation and tutorials: =20
=20
perlref
perlreftut
perllol
perldsc
=20
a quick and dirty (and UNTESTED) answer to your specific question about how=20=
=20
to remove=20
non-significant items from a referenced array is as follows: =20
=20
ROW:
for (my $i =3D 0; $i < @$some_data; ++$i) {
if ($some_data->[$i][0] eq '') {
splice @$some_data, $i, 1;
redo ROW;
}
}
=20
however, a different approach might be more effective: only take some actio=
n=20
(e.g., inserting=20
a row into a pdf table) if the row data is significant. for instance (als=
o=20
UNTESTED): =20
=20
for (my $i =3D 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=
=20
de-referenced sub-array
}
}
=20
also - take a look at hashes of hashes for implementing this kind of data =20
table (discussion and=20
examples in perldsc - perl data structures cookbook). =20
=20
also - always use warnings; and use strict; =20
=20
hth -- bill walters =20
=20


-------------------------------1168460109
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Content-Language: en





Arial"=20
bottomMargin=3D7 leftMargin=3D7 topMargin=3D7 rightMargin=3D7> e_document=20
face=3DArial color=3D#000000 size=3D2>


hi ben --  

 

In a message dated 1/10/2007 10:35:00 A.M. Eastern Standard Time,=20
beagle@alinean.com writes:

 

> I am making a PDF , which using PDF::Table I am making a table ins=
ide=20
that PDF.
>
> What I am trying to do is make the table dynamic,=
=20
cause I am passing variables
> and I do not want a blank table row if=20=
the=20
variable is empty. This is what I
> have tried so far:
>
>=
; my=20
$some_data =3D[
>     ["HP Hardware", "Total=20
Cost"],
>     [$hardware1,=20
$hardwareValue1],
>        &nb=
sp;   =20
[$hardware2,=20
$hardwareValue2],
>        &nb=
sp;   =20
[$hardware3,=20
$hardwareValue3],
>        &nb=
sp;   =20
[$hardware4,=20
$hardwareValue4],
>        &nb=
sp;   =20
[$hardware5,=20
$hardwareValue5],
>        &nb=
sp;   =20
[$hardware6,=20
$hardwareValue6],
>        &nb=
sp;   =20
[$hardware7,=20
$hardwareValue7],
>        &nb=
sp;   =20
[$hardware8,=20
$hardwareValue8],
>        &nb=
sp;   =20
[$hardware9,=20
$hardwareValue9],
>        &nb=
sp;   =20
[$hardware10,=20
$hardwareValue10],
>        &n=
bsp;   =20
[$hardware11,=20
$hardwareValue11],
>        &n=
bsp;   =20
[$hardware12,=20
$hardwareValue12],
>        &n=
bsp;   =20
[$hardware13,=20
$hardwareValue13],
>        &n=
bsp;   =20
[$hardware14,=20
$hardwareValue14],
>        &n=
bsp;   =20
[$hardware15, $hardwareValue15],
>     ];
>=20

> for (my $i=3D0; $i< scalar($some_data); $i++) {
>=20

>           &n=
bsp;=20
if ($hardware[$i] eq "") {
>=20

>           &n=
bsp;=20
}
>
> }
>
> I am thinking if the variable is blank=
I=20
want to delete the row from
> $some_data, I donâ€=99t know the syn=
tax to do=20
it,
>
> Any help or suggestions would be helpful, thanks
>=
;=20

> Ben

 

for detailed answers to your questions (and many others that are implie=
d),=20
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=20
to remove

non-significant items from a referenced array is as=20
follows:  

 

    ROW:

    for (my $i =3D 0;  $i < @$some_data;  +=
+$i)=20
{

        if ($some_data->[$i][0] e=
q=20
'') {

            spli=
ce=20
@$some_data, $i, 1;

            redo=
=20
ROW;

            } IV>
        }

 

however, a different approach might be more effective: only take some=20
action (e.g., inserting

a row into a pdf table) if the row data is significant.   for=
=20
instance (also UNTESTED):  

 

    for (my $i =3D 0;  $i < @$some_data;  +=
+$i)=20
{

        if ($some_data->[$i][0])=20
{  # if row data significant...

           =20
insert_in_my_pdf_table(@{ $some_data->[$i] });  # pass items of=20
de-referenced sub-array

            } IV>
        }

 

also - take a look at hashes of hashes for implementing this kind of da=
ta=20
table (discussion and

examples in perldsc - perl data structures cookbook).   >
 

also - always  use warnings;  and  use strict; &nbs=
p;=20

 

hth -- bill walters  

 


-------------------------------1168460109--

--===============1918579394==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============1918579394==--