First of all the following doesn't make sense. sub is called with the same parameters every time.

foreach (@temp) { sub($x0, $y0, $x1, $y1, @temp) } }
But lets see if I understand your problem. It seems you have an unnecessary loop there. I commented that out. Also I changed your inner loops slightly, they have to stop looping after they get to the last 4 values.

Now all there is left to do is to take your best attempt and wrap the corrected code for the other hash around it, substituting $x2...$y3 with @temp. I put the inner loop into a sub, makes it easier to compare to your version

foreach my $key (keys %other_hash) { # foreach (@{$other_hash{$key}} # { for (my $i=0; $i<=@{$points_by_name{$key}}-4; $i+=2) { innerloop( @{$other_hash{$key}}[$i..$i+3] ); } # } }
and
sub innerloop { my ($x2,$y2,$x3,$y3)= @_; foreach my $key (keys %points_by_name) { # foreach (@{$points_by_name{$key}} # { for (my $i=0; $i<=@{$points_by_name{$key}}-4; $i+=2) { sub(@{$points_by_name{$key}}[$i..$i+3], $x2, $y2, $x3, + $y3) } # } } }
Note I didn't test this. Might still be some bug in it.

About your 'keeping track' problem: You have $key, you have $i, what else do you need to know about the line you are evaluating? Pass them into the sub if the sub needs to know


In reply to Re: Subroutine Subtrefuge by jethro
in thread Subroutine Subtrefuge by AF_One

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.