Hello Monks,
My question is this. I am looking for a more Perl-ish way to accomplish the following:
NUMBER:
for (3 .. 8) {
my $pdu_num = $_;
$pdu_num = 11 - $pdu_num unless defined $order;
while (@nodes) {
my $node = shift @nodes;
$map{$node} = $pdu . '['.$pdu_num.']';
next NUMBER;
}
}
What's happening here is I need to increment one item of a list (the for...) and append it to the end of an element of the array, then skip to the next number and pair it up with the next element of the array. The
$order variable is a flag to determine whether I need to arrange them in ascending (3..8) or descending (11 -n) order.
Another disturbing fact is the loop label. While I recognize that this is valid in Perl, it has a haunting goto-statement quality about it. Improvements?
Also, would it be considered more Perl-ish to write:
for my $pdu_num (3 .. 8) {
while my $node (@nodes) {
# more code here...
}
}
I couldn't think of a better way to word my title, although I'm sure there is probably a term for what I'm doing here.
Thanks in advance for your time and replies.
This message brought to you by the complexities of Avocent AlterPath ACS.
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.