The requirements are not entirely clear, and you don’t explain how the logic is failing. Taking the specification together with the pseudocode shown, the implementation in Perl could be as simple as the following (skeleton code, untested):

#! perl use strict; use warnings; my $file = 'config.txt'; my $prefix = 'ge-3/1/0.'; my ($router, $max_x, $max_y, $max_z) = get_values($file); my $max = $max_z // $max_y // $max_x // 0; set_interface($router, $prefix . $_) for 1 .. $max; sub get_values { ... } sub set_interface { ... }

The key line here is my $max = $max_z // $max_y // $max_x // 0; which uses the logical defined-or operator.

If this logic doesn’t meet your needs (and I doubt that it will), it may at least help you to clarify the requirements by highlighting the way(s) in which it falls short.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,


In reply to Re: Identify values from variables by Athanasius
in thread Identify values from variables by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.