It works fine for me both at the command line and browser, and I don't see anything immediately wrong with it. Try turning on warnings and use the strict pragma; those may help describe the problem more closely. Also, be aware if you're only checking the output in a web browser that you haven't actually created an html document per your content-type header. To do that, you need to wrap your output in
<html> and preferably
<body> tags. Modern browsers won't care, but it wouldn't hurt. A cleaned up version of your code following all that advice might look like this:
#!/usr/bin/perl -w
use strict;
my @skuid=("11021","11022","11023");
my @name=("mt. eden","dom perignon","veuve cliquot");
my @price=("45.99","135.99","79.99");
print "Content-type:text/html\n\n";
print "<html><head><title>Test script</title></head><body>\n";
foreach my $skuid (@skuid) {
print "SKUID:$skuid\n";
}
foreach my $name (@name) {
print "NAME:$name\n";
}
foreach my $price (@price){
print "PRICE:$price\n";
}
print "</body></html>";
As an aside, be inclined to use the CGI.pm module rather than manual html if you're planning on doing more serious CGI work in the future.
If none of this helps, more information on your platform, perl version (with perl -v), and browser would be helpful.
Update:
I just couldn't help myself... the problem I think you're trying to solve screams for a hash. Here's how I would actually do it (note I'm a big fan of using CGI.pm functionally):
#!/usr/bin/perl -w
use strict;
use CGI ":standard";
my %wines = (11021 => ["Mt. Eden", "45.99"],
11022 => ["Dom Perignon", "135.99"],
11023 => ["Veuve Cliquot", "49.99"]);
print header, start_html({-title=>'Wines'}),
table({-border=>1},
[Tr([th(["SKUID",
"Name",
"Price"
]),
map td([$_,
$wines{$_}->[0],
$wines{$_}->[1]]),
sort keys %wines
])
]),
end_html;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.