Hi monks,
I have a input file like
225 2198
374 315
420 1149
57 2611
using the above input, i need to find out "What is the least value while doing the division operation". For example 225/2198=0.102365787, 374/315=1.187301587, from here i need to know what are the two values gives the least value.
I have tried the below code, it is working fine but i need to optimize this code.
open(INP, $ARGV[0]);
$minimumAmount=100;
while (<INP>)
{
if (/(\d+) (\d+)/)
{
if ($minimumAmount > ($1/$2))
{
$minimumAmount=($1/$2);
$amount=$1;
$weight=$2;
}
}
}
close(INP);
print "$amount\t$weight";
what i'm looking is to increase the speed
if it is possible in unix command itself, it would be best
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.