bini has asked for the wisdom of the Perl Monks concerning the following question:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perplexed Winemaking Monk
by chromatic (Archbishop) on Aug 23, 2000 at 08:43 UTC | |
You might want a different datastructure, though, so take a look at perlref and perldsc. A list of lists would do the trick nicely. | [reply] [d/l] |
|
Re: Perplexed Winemaking Monk
by Russ (Deacon) on Aug 24, 2000 at 02:56 UTC | |
You have:
In other words, for each index in @combo (the 0 .. $#combo part), set $Idx to that index and run the body of the block. This accomplishes the same thing as your code, but doesn't leave an unused variable ($n) lying around. It specifically uses the index of each element in @combo, which makes the code easier to follow and maintain. Besides, it looks so much cooler... ;-) Welcome to Perl in general and Perl Monks in specific. We're glad to have you. Russ | [reply] [d/l] [select] |
|
RE: Perplexed Winemaking Monk
by Adam (Vicar) on Aug 23, 2000 at 20:36 UTC | |
That said, I'm not entirely sure of your goal here. I'm going to guess that you want to print out the three data points for each wine. As chromatic suggested, you probably want a better data structure. May I suggest a hash? Since the skuid is probably unique, I would make that the key. Each value would then be an array containing the vinyard and the price. Then you just dump the contents of the hash. (crudely using data::dumper, or nicely as I do below.) Here is my version: Note that I assumed from your print content text/html line that this was generating html, so I did it using CGI.pm's procedural methods. You can also use CGI.pm oo methods, but I didn't feel like it. | [reply] [d/l] [select] |