in reply to Perplexed Winemaking Monk
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:#!/usr/bin/perl @skuid=("11021","11022","11023","92523002", "02196005","92196019","92176184","92305069", "92305070","92305054","14316002","92620206", "92503001"); @name=("mt. eden","dom perignon","veuve cliquot", "Arcadian Pinot Noir Sl Holl","Au Bon Climat Pinot Noir La Baug +e", "Au Bon Climat Pinot Noir Laetitia", "Bannister Pinot Noir Seghesio Vineyard", "Broadley Pinot Noir Claudias Choice", "Broadley Pinot Noir Marcille Loraine", "Broadley Pinot Noir Reserve","Castalia Pinot Noir Rochioli Vyd +", "Coldstream Hills Pinot Noir","Costa De Oro Pinot Noir"); @price=("45.99","135.99","79.99","24.99","24.99", "39.99","26.99","39.99","29.99","23.99", "29.99","17.99","19.99"); @combo=($skuid,$name,$price); print "Content-type:text/html\n\n"; $n==0; foreach $item(@combo) { print "SKUID:$skuid[$n]\n"; print "NAME:$name[$n]\n"; print "PRICE:$price[$n]\n"; $n++; }
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.#!/usr/bin/perl use strict; # Always. use CGI ':standard'; my %winelist = ( "11021" => ["mt. eden", "45.99"], "11022" => ["dom perignon", "135.99"], "11023" => ["veuve cliquot", "79.99"], "92523002" => ["Arcadian Pinot Noir Sl Holl", "24.99"], "02196005" => ["Au Bon Climat Pinot Noir La Bauge", "24.99"], "92196019" => ["Au Bon Climat Pinot Noir Laetitia", "39.99"], "92176184" => ["Bannister Pinot Noir Seghesio Vineyard", "26.99"], "92305069" => ["Broadley Pinot Noir Claudias Choice", "39.99"], "92305070" => ["Broadley Pinot Noir Marcille Loraine", "29.99"], "92305054" => ["Broadley Pinot Noir Reserve", "23.99"], "14316002" => ["Castalia Pinot Noir Rochioli Vyd", "29.99"], "92620206" => ["Coldstream Hills Pinot Noir", "17.99"], "92503001" => ["Costa De Oro Pinot Noir", "19.99"], ); print header(), start_html(); print "\n\n<!-- This page generated by a script written by Adam at Per +lMonks.org -->\n\n"; print h1( "My Wine Collection" ), "\n\n"; print table( {-width, '100%'}, TR( td( {-width, '20%'}, "SKUID" ), td( {-width, '60%'}, "WINE" ), td( {-width, '20%'}, "PRICE" ) )), "\n"; my $wine; foreach $wine (keys %winelist) { print table( {-width, '100%'}, TR( td( {-width, '20%' }, "$wine" ),"\n", td( {-width, '60%' }, "$winelist{$wine}[0]" ), td( {-width, '20%' }, "$winelist{$wine}[1]" ) )), "\n"; } print end_html();
|
|---|