cal has asked for the wisdom of the Perl Monks concerning the following question:
for ($x=1; $x <= $total_elements +1; $x++) {$varname = "fname_menu$x";$NEW_BUS_TXT = ${"NEW_BUS_TXT$x"}; $$varname = " <table border='1' width='100%' bgcolor='#BBEEEE'> <tr> <td width='100%'> <B>($x.)Using the pull down menu Select a member</B> ${NEW_PD$x} }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Really need help with loop variable
by demerphq (Chancellor) on Feb 13, 2002 at 18:12 UTC | |
Sorry to do this to you but... <Lecture>
So now lets look at your code: Hmm.. first thing I see (beyond the above serious issues :-)is that your code is messy and confusing, so Ill clean it up a bit.. But I cant. Because there is no trailing " to finish your quoted section. So Ill make some dangerous assumptions about your code and show you what this could would look like (if I used symbolic refs that is) This stuff is scary... Sorry, but it's true. What I think you are doing is trying to do is build a numbered set of tables, but the problem is where is the end of the table/row/cell? Is it in the mysterious symbolic reference ${NEW_PD$x}? And what is this for:$NEW_BUS_TXT = ${"NEW_BUS_TXT$x"}; So to be honest there isnt a lot that I (or IMO anyone else here) can do with this code. OTOH: I can give you some more tips.
Anyway, hope this is a bit of help at least. And please dont give up. Leave that use strict; right at the top of every script, exactly where it belongs. Fight and fight until all those nasty errors go away, in the end youll be happy you did (not to mention being a far better programmer).
Yves / DeMerphq | [reply] [d/l] [select] |
|
Re: Really need help with loop variable
by George_Sherston (Vicar) on Feb 13, 2002 at 18:32 UTC | |
"can you throw me up a hatchet so I can cut away this bunch of ivy that's getting in my way" ... you might well say, "hey, no, come down here, and then go inside and you'll find there's a staircase that will take you where you want to go". (Also, if you'd seen a lot of people climbing the outside of the building and falling off and eventually going into the staircase, you might get a bit short with them.) As to specific problems with the above, I would think particle is correct - and indeed you do it "right" in your line 2, where you have ${"NEW_BUS_TXT$x"}. But I say ' "right" ' rather than 'right' advisedly. The Camel says of symbolic references, which is what you're doing, "very powerful, and slightly dangerous". And I think in this case you probably don't need the power, and you certainly don't need the danger. I haven't quite figured out exactly what you are trying to achieve, but I guess you have somewhere a lot of defined variables called things like $NEW_PD1, $NEW_PD2, each of which is the html for a pull down menu. Now the first thing I'd say is that if that's correct you would in general be far better off putting those values an array, and iterating through the array. BUT... in this specific instance what I would really recommend would be using CGI.pm. As you may know, this industry-standard module has lots of great functions which, inter alia allow you to generate pull down menus (popup_menu()) on the fly. Without knowing more about what you want to put into these menus, I can't give you any example code that will be any use; but I am quite certain that using CGI in this way would save you a lot of trouble. Even if you've never used this module before (even if you've never used any module before) you would find that it repays your effort in learning to get it working. Take a look in http://cpan.valueclick.com/modules/by-category/15_World_Wide_Web_HTML_HTTP_CGI/CGI/CGI.pm-2.80.tar.gz to see the documented code, or use Super Search here to find resources to help you do this if needs be. It wd be very interesting to see what you produce if you decide to go this way, and monks will be delighted to help you perfect it, I doubt not. § George Sherston | [reply] [d/l] [select] |
|
Re: Really need help with loop variable
by boo_radley (Parson) on Feb 13, 2002 at 18:55 UTC | |
| [reply] [d/l] [select] |
|
Re: Really need help with loop variable
by particle (Vicar) on Feb 13, 2002 at 17:27 UTC | |
how about some quotes around the bareword "NEW_PD"??? ~Particle | [reply] |
|
Re: Really need help with loop variable
by Caillte (Friar) on Feb 13, 2002 at 18:19 UTC | |
To get your code to work you need something like this:
To get your code to actually do something useful will take longer. How about you let us know a little about what you want to do here. This page is intentionally left justified. | [reply] [d/l] |
| A reply falls below the community's threshold of quality. You may see it by logging in. | |