in reply to Perl/Html Question - rows are not aligned between different columns

Thanks everyone for your suggestions. I finally got it fixed using a combination of fonts, cell paddings, and cell spacings between table rows. My next question is as I dynamically generate a new table rows and columns based on user's input, how do I keep track of their values using some dynamically generated variables as well? For example:
while ($i < $run) { $i++; print qq{<td rowspan="$rowsp"><table border="1"><col width="165"> +<tr><td><br></td></tr>}; my $j = 0; while ($j <= $group) { $j++; print "<tr><td><br></td></tr>"; print "<tr><td><br></td></tr>"; print '<tr align="center"><td><input type="text" name="test1" + size="15"></td></tr><tr align="center"><td><input type="text" name=" +mem1" size="15"></td></tr><tr align="center"><td><input type="text" n +ame="mem2" size="15"></td></tr>'; } print "</table></td>"; }
name=test1 above will be generated many times but it needs to have a different variable name everytime to store a different value associate with it. Any thought? Thanks.
  • Comment on Re: Perl/Html Question - rows are not aligned between different columns
  • Download Code

Replies are listed 'Best First'.
Re^2: Perl/Html Question - rows are not aligned between different columns
by dragonchild (Archbishop) on Nov 03, 2007 at 13:48 UTC
    Why is it that people are willing to learn how to actually do the task at hand when it has to do with physical things (driving, power tools, etc), but have this INSANE notion that they can just sit down at a computer and whip out the next Facebook in a weekend?!

    Here is what you need to do, in this order:

    1. Stop working on your project. Now.
    2. Go out and buy a copy of Learning Perl.
    3. Read said copy of Learning Perl
  • Come back to your project and throw it all away.
  • Start again, this time actually thinking through what you're trying to do.

    I'm not "being mean." I'm trying to teach you how to fish.


    My criteria for good software:
    1. Does it work?
    2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
      • Um, Learning Perl explicitly assumes that you know how to program and so doesn't try very hard to teach basic programming practice. At least that was the case with earlier editions.

        I'd suggest something aimed at beginning programmers like Beginning Perl. At least it is available for free, and it includes a chapter on how to write CGI programs. (Using CGI.pm's methods rather than a template system, but it is still likely to give some helpful ideas.)

        Of course if you wanted to be nasty, then you could recommend starting with Structure and Interpretation of Computer Programs. (For those who don't know it, this is an excellent book. It is available online but I recommend buying a copy, reading it, and re-reading it every few years. I'm getting due to re-read it again. That said, it is pitched at a fairly high level, and for most people will push them to completely rethink how they think about programming.)

        The book that I really wish I could get lots of people to read is Code Complete 2. Of course they never will since it is a big fat book with tons of important detail. But all of that detail is valuable knowledge that programmers really should know on some level. (Preferably you want it integrated into their bones so they just do it naturally. Hey, if I'm going to dream...)

    Re^2: Perl/Html Question - rows are not aligned between different columns
    by tilly (Archbishop) on Nov 03, 2007 at 13:53 UTC
      Learn to use different quoting styles and then you can easily interpolate in variables and have quotation marks.
      my $foo = "bar"; print qq{"$foo"}; # prints "bar" with the quotes
      and now you can replace things like test1 with variables and have your names be dynamic.

      BTW I'm going to second the previous suggestion to learn about the importance of dividing up content and presentation. While it is conceptually easy to just mix your code and gobs of HTML, the resulting code quickly becomes unmaintainable spaghetti.

      The easiest way to do that is to use a templating system. It is a little old, but this survey is still a decent introduction to the basic kinds of templating systems out there, and the ones that it mentions are still readily available. (Personally I like Template Toolkit.)