What, dear monks, is the most efficient way of getting these arrays:
my @x_values_for_points_above_the_trend_line; my @y_values_for_points_above_the_trend_line; my @distances_above_the_trend_line; my @x_values_for_points_below_the_trend_line; my @y_values_for_points_below_the_trend_line; my @distances_below_the_trend_line; my @x_values_for_points_on_the_trend_line; my @y_values_for_points_on_the_trend_line; # The contents of these arrays have corresponding values in the same a +rray positions.
... into a lookup hash so that I can perform operations like the following:
my $count_A = -1; my @regions_A_array; foreach (@x_values_for_points_above_the_trend_line) { $count_A++; my $x_value_SM = $_; my $y_value_SM = $y_values_for_points_above_the_trend_line[$count_A] +; my $Select_area_above_trendline = " SELECT DISTINCT A.Region FROM Temp_table_A A, Temp_table_B B WHER +E A.Region = B.Region AND A.SM = ".$x_value_SM." AND B.SM = ".$y_valu +e_SM." "; my $sth_atl = $dbh->prepare($Select_area_above_trendline) or die "Co +uldn't prepare query: ".$dbh->errstr; $sth_atl->execute() or die "Couldn't execute query: ".$sth_atl->errs +tr; my @regions_A; while (@regions_A = $sth_atl->fetchrow_array) { push (@regions_A_array, @regions_A); } my @regions_A_array = r(@regions_A_array); # This is to remove du +plicates from the array } # The subroutine below removes duplicates sub r{ keys%{{map{$_,1}@_}} }
...... with the added functionality of printing out each region in the array @regions_A_array with the $distances_below_the_trend_line[$pos] value.


By the way, I accept that it looks like this process has been badly designed. It is an evolved piece of code.

In reply to Making do with a badly designed process by Win

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.