Hi Monks, I was trying to write a code to get the minimum and maximum value in a given field. The code doesn't seem to work fine when I run it on large files and it multiplies the file size and adds unwanted records. I can get the output correctly for this example but it words faulty on large files. Please help me to correct the code. I get the correct output for this example:- Output:- Books    6    159290954    159331385    +    Author
Here is my full code with example:-
#!/usr/bin/perl open(FH, $ARGV[0]) || die("Cannot open:$!"); while (<FH>) { ($Query, $Score, $Start, $End, $one, $two) = split; if ( ! exists ( $hash{$Query} ) ) { $hash{$Query}[0] = $Score; $hash{$Query}[1] = $Start; $hash{$Query}[2] = $End; $hash{$Query}[3] = $one; $hash{$Query}[4] = $two; } else { if ( $hash{$Query}[1] > $Start ) { $hash{$Query}[0] = $Score; $hash{$Query}[1] = $Start; $hash{$Query}[2] = $End; $hash{$Query}[3] = $one; $hash{$Query}[4] = $two; } } if ( ! exists ( $hash2{$Query} ) ) { $hash2{$Query}[0] = $Score; $hash2{$Query}[1] = $Start; $hash2{$Query}[2] = $End; $hash{$Query}[3] = $one; $hash{$Query}[4] = $two; } else { if ( $hash2{$Query}[2] < $End ) { $hash2{$Query}[0] = $Score; $hash2{$Query}[1] = $Start; $hash2{$Query}[2] = $End; $hash{$Query}[3] = $one; $hash{$Query}[4] = $two; } } } foreach $Query ( keys (%hash) ) { foreach $Query ( keys (%hash2) ) { print "$Query\t$hash{$Query}[0]\t$hash{$Query}[1]\t$hash2{$Query}[2 +]\t$hash{$Query}[3]\t$hash{$Query}[4]\n"; } } close(FH); __DATA__ Books 6 159290954 159291342 + Author Books 6 159294558 159294653 + Author Books 6 159316253 159316398 + Author Books 6 159330999 159331385 + Author Books 6 159290971 159290997 + Author Books 6 159316253 159316398 + Author Books 6 159330999 159331289 + Author Books 6 159316268 159316398 + Author Books 6 159330999 159331245 + Author
Thanks in advance

In reply to Parsing and Finding Max Min by Perl_Crazy

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.