"which I will try to build & use nested loops in, when I can get it functioning"

Exactly the wrong way around! Think structure (overall program structure and data structure) first, then details. By the time you've written the details it is far too late to go back and rethink the structures.

For complicated projects it's often said "write the first version to throw away". It's only when the first version has been written that you have an idea of how you perhaps should have written it. Getting a better first cut is mostly a matter of experience.

A major red flag (code smell/stink) is variable names with index numbers in them. Whenever you find yourself doing that, change to using an array. For your current task however that just isn't an issue because you don't need to store the intermediate values at all. Consider:

#!/usr/bin/perl use strict; use warnings; my $wheel = 26.5; my @chainWheels = qw (42 32 22); my @cogs = qw (11 13 15 17 19 21 24 28 32); print "Wheelsize: $wheel\n"; print "Chainwheels: @chainWheels\n"; print "Sprockets: @cogs\n\n"; for my $chainSel (1 .. @chainWheels) { my $wheelMul = $wheel * $chainWheels[$chainSel - 1]; print "Chain wheel: $chainSel ratios: \n"; for my $cogSel (1 .. @cogs) { printf "%d: %5.2f ", $cogSel, $wheelMul / $cogs[$cogSel - 1]; } print "\n"; }

Prints:

Wheelsize: 26.5 Chainwheels: 42 32 22 Sprockets: 11 13 15 17 19 21 24 28 32 Chain wheel: 1 ratios: 1: 101.18 2: 85.62 3: 74.20 4: 65.47 5: 58.58 6: 53.00 7: 46.38 8: 39. +75 9: 34.78 Chain wheel: 2 ratios: 1: 77.09 2: 65.23 3: 56.53 4: 49.88 5: 44.63 6: 40.38 7: 35.33 8: 30.2 +9 9: 26.50 Chain wheel: 3 ratios: 1: 53.00 2: 44.85 3: 38.87 4: 34.29 5: 30.68 6: 27.76 7: 24.29 8: 20.8 +2 9: 18.22
True laziness is hard work

In reply to Re: I'm trying to get a numeric array by GrandFather
in thread I'm trying to get a numeric array by fatmac

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.