Well, actually, I haven't coded the whole thing...it was just looking ugly as I started...I started out thinking I'd just check to see if I could find two of my picks that would be roughly the same value as the other guys pick, so here is the code I had:

foreach my $rec1 (@to_trade1) { foreach my $rec2 (@to_trade1) { if ($rec1->{"PICK"} != $rec2->{"PICK"}) { my $trade_diff = $pot_trade_val - $rec1->{"VALUE"} - $rec2->{" +VALUE"}; if (($trade_diff > 49) && ($trade_diff < 101)) { $to_trade[$trade_cntr]->{"PICK_LIST"} = sort {$a <=> $b} ($r +ec1->{"PICK"}, $rec2->{"PICK"}); $to_trade[$trade_cntr]->{"VALUE"} = $trade_diff; }

That should give you the idea of where I was going with the following understanding:

$pot_trade_val The value of the pick I want plus the 16th round pick held by the same team
$rec1 and $rec2 The same array copied twice and this is the list of picks I currently have.
$to_trade This is the set of picks that is within my tolerance to trade 50-100 points difference, of course, I'd walk this list and pull the one closest to 50

So, as I was going through this, I thought that it would end up pretty ugly and I'd only be able to account for say groups of three picks before the logic gets even worse. Thus, I thought it might be easier to value all my picks once, and then each time I was looking for a trade, I could just grep and sort the array of already calculated values! Sound like a good approach?


In reply to Re: Re: array problems by bfish
in thread array problems by bfish

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.