how to find the biggest ????

M

mkl

If I have a file ,named txt

###############
a (298:298) (9:9)
b (2:2)
c (3:3)
d (5:5)
############################


how do i select the biggest one and print ?
 
A

Anno Siegel

mkl said:
If I have a file ,named txt

###############
a (298:298) (9:9)
b (2:2)
c (3:3)
d (5:5)
############################


how do i select the biggest one and print ?

The biggest what?

Someone is going to suggest sorting the items and taking the last one.
That's inefficient.

Anno
 
G

Gunnar Hjalmarsson

mkl said:
If I have a file ,named txt

###############
a (298:298) (9:9)
b (2:2)
c (3:3)
d (5:5)
############################


how do i select the biggest one and print ?

#!/usr/bin/perl
use strict;
use warnings;

my $value = 0;
my $biggest;
open FH, 'txt' or die $!;
while (<FH>) {
if ( (/([\d:]+)\)\s*$/)[0] > $value ) {
$biggest = $_;
$value = $1;
}
}
close FH;
print "Biggest record:\n$biggest\n";
 
H

Helgi Briem

If I have a file ,named txt

###############
a (298:298) (9:9)
b (2:2)
c (3:3)
d (5:5)
############################


how do i select the biggest one and print ?

Biggest? Which one is biggest? Is d bigger than a?
(298:298) bigger than (9:9). Which values do you wish
to compare?
 
C

Chris Mattern

mkl said:
If I have a file ,named txt

###############
a (298:298) (9:9)
b (2:2)
c (3:3)
d (5:5)
############################


how do i select the biggest one and print ?
Biggest what? And how are you determining
that x is bigger than y?

Chris Mattern
 
M

mkl

I want to compare number and print the whole line,
I know the biggest value is 298 in this file and
print a (298:298) (9:9)


thanks your help!!!!
 
J

Jay Tilton

[Please do not top-post replies. Please trim reply-quoted material to
the minimum necessary to establish context. See the clpm posting
guidelines at http://mail.augustmail.com/~tadmc/clpmisc.shtml for
explanations and other good advices.]

: "Chris Mattern" <[email protected]> ??? ???...
: > mkl wrote:
: > > If I have a file ,named txt
: > >
: > > ###############
: > > a (298:298) (9:9)
: > > b (2:2)
: > > c (3:3)
: > > d (5:5)
: > > ############################
: > >
: > > how do i select the biggest one and print ?
: > >
: > Biggest what? And how are you determining
: > that x is bigger than y?
:
: I want to compare number and print the whole line,
: I know the biggest value is 298 in this file and
: print a (298:298) (9:9)

Have you tried writing any code on your own yet?

One possible way,

use List::Util qw(reduce max);
my $big = reduce{max($a=~/\d+/g)>max($b=~/\d+/g)?$a:$b} <DATA>;

__DATA__
a (298:298) (9:9)
b (2:2)
c (3:3)
d (5:5)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,139
Messages
2,570,805
Members
47,356
Latest member
Tommyhotly

Latest Threads

Top