LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 01-08-2013, 08:12 PM   #1
eminempark
Member
 
Registered: Oct 2012
Posts: 56

Rep: Reputation: Disabled
Perl to find max and min values


I need a perl script that can print the maximum value and the minimum value from a text file called "one.txt".
For example:
Code:
#ID Temperature
1 25
2 34
3 35
4 23
5 24
:
:
3000 24
The output should show:
Code:
Max temperature is:ID 2 Temperature 35
Min temperature is:ID 3 Temperature 23
I know there is a lot of perl script that posted before to find max and min value. But mostly they are in single column. Anyone can help?
 
Old 01-09-2013, 04:45 AM   #2
tshikose
Member
 
Registered: Apr 2010
Location: Kinshasa, Democratic Republic of Congo
Distribution: RHEL, Fedora, CentOS
Posts: 134

Rep: Reputation: 30
Code:
while (<>) {
  ($id, $temp) = /(\d+)\s+(\d+)/;
  ($min_id, $min_temp) = ($id, $temp) if ($temp < $min_temp or ! defined $min_temp);
  ($max_id, $max_temp) = ($id, $temp) if ($temp > $max_temp or ! defined $max_temp);
}
print "Max temperature is:ID $max_id Temperature $max_temp\n";
print "Min temperature is:ID $min_id Temperature $min_temp\n";
 
  


Reply

Tags
minimum, numbering, perlscript, text processing


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
min-max-x buttons to left? danbuter Bodhi 6 02-15-2011 07:06 AM
regex problem to find min,max length words in file gvanto Linux - Newbie 4 01-30-2011 05:34 PM
Modifying the Linux IP Stack to get TTL min/max/avg values mpk_india Linux - Kernel 0 12-31-2008 04:36 AM
C++: Extract numbers from an input file, find av & max, min programmernew Programming 4 10-27-2008 10:00 AM
Min/Max buttons? andykap Linux - General 3 12-15-2003 12:09 AM


All times are GMT -5. The time now is 05:13 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration