bory has asked for the wisdom of the Perl Monks concerning the following question:

Hi great perlmonks! I have the following stupid problem maybe because i'm too tired In an html form i have some textboxes:
..... print "<tr><td$idold[$i]</td<td><input type=textbox name=\"typeold\" > +</td></tr>"; .... print "<tr><td$idnew[$n]</td<td><input type=textbox name=\"typenew\" > +</td></tr>"; ......
And in an cgi script i want to print for each $idnew$n/$idold$ithe corresponding values from the textbox:
my @idnew=param ('idnew'); my @idold=param ('idold'); my @typenew=param ('typenew'); my @typeold=param ('typeold'); for (my $eu=0;$eu<=(scalar(@idnew)/2-1);$eu++) { print "<h2>New$idnew[$eu]/$typenew[$eu]</h2>"; } for (my $io=0;$io<=(scalar(@idold)/2-1);$io++) { print "<h2>New$idold[$io]/$typeold[$io]</h2>"; }
It doesn't print $typeold$io( but it prints @typeold with the whole values if I do so ) Thanks for understanding me.

Replies are listed 'Best First'.
Re: printing an array
by castaway (Parson) on Mar 30, 2004 at 08:28 UTC
    You just have a small typo in your script, I assume because you copied the first for-loop to produce the second one.. You forgot to change the $eu<=(scalar(@idold)/2-1); to $io<=(scalar(@idold)/2-1);.

    In fact, two typos. I assume that <h2>New$idold[$io]/$typeold[$old]</h2> should actually be <h2>New$idold[$io]/$typeold[$io]</h2>, since that is the counter for that for-loop.

    Note: using 'use warnings;' at the top of your script would have pointed out that you were using the $old variable only once, and might have led you to the solution. Also, scoping your variables properly (ie my $eu and my $io) would have helped, as it would have died with an Undefined variable error when encountering the $eu the second time around..

    C.

      I did the update, I also put "use warnings" in my code but it's the same problem. Thanks

        As pelagic mentions below, test your data. It looks like what you belive to be in the array actually is in it's first array slot.

        Cheers, Sören

Re: printing an array
by pelagic (Priest) on Mar 30, 2004 at 11:48 UTC
    Why don't you just try to find out what really is in your arrays?
    ... use Data::Dumper; ... print Dumper (\@idold); print Dumper (\@idnew);

    then you know at least where to look for your problem ...
    pelagic

    -------------------------------------
    I can resist anything but temptation.