Hash keys are strings, so all you need to do is concatenate the 'item' or 'qty' with your index. The postincrements ('++') you have within the keys are redundant and will give you an error anyhow. So then we could clean your code up: for my $i ($i=1; $i<=243; $i++) {
print FH "$FORM{'item' . $i}\t$FORM{'qty' . $i}\n"
if $FORM{'qty' . $i};
}
Though I'd be more likely use printf and an array slice for clarity in this case:for (1..243) {
printf FH "%s\t%s\n", $FORM{"item${i}"}, $FORM{"qty${i}"}
if $FORM{"qty${i}"};
}
The braces aren't strictly necessary here, but will prevent confusion in the future if you need to append a static string after the interpolated variable.
|