Since you described this as your first Perl program, let me
comment on your loop. The others have given good advice
for the data structures, so I'll just make a quick suggestion
about your actual code.
You have:
$n == 0;
for (loop condition){
$n++
}
- Use = for assignment, == for testing. This line
doesn't actually do anything, except cause a warning. It
tests whether $n (an undefined value) is equal to zero.
- On the subject of warnings, you are running with
warnings enabled, right? <nobr>#!/usr/bin/perl -w</nobr>
at the top of your script will enable many useful warnings.
Don't leave home without it. :-)
- On the subject of global variables ($n is a global, in
your code), don't use them. Adam has <nobr>use strict; #Always</nobr>
in his code. This is a good idea. It will help you avoid
problems.
- Looping: Here is a slightly more idiomatic way to do
your loop:
for my $Idx (0 .. $#combo){
print "SKUID:$skuid[$Idx]\n";
print "NAME:$name[$Idx]\n";
print "PRICE:$price[$Idx]\n";
}
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
Brainbench 'Most Valuable Professional' for Perl
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.