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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |