HELP: compare floating point variables??


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting HELP: compare floating point variables??
# 1  
Old 06-19-2009
Question HELP: compare floating point variables??

Hi All,

I got this script that pulls the Amps value from our RPC's , I basiclly want to compare the valued with a "limit" value -- if the numbers match or are greater than the definded value ...do something. My problem is I cant seem to figure out how to compare floating points...


here is the value when the script is run ...
#./rpmamp.pl
13.1 Amps
12.7 Amps

Here is the code...
Code:
#!/usr/bin/perl
#$host = $ARGV[0];

use Net::Telnet;
$telnet = new Net::Telnet ( Timeout=>10,
 		            Binmode=>0,
		            Input_Log=>'inputlog',		
		            Dump_Log=>'scriptlog',		
                            Errmode=>'die');
## Get the temp from the top RPC ##
$telnet->open ("10.2.4.2") or die("Cannot open");
##$telnet->waitfor('/Enter username>$/i');
##$telnet->print("user1");
##$telnet->waitfor('/Enter password>$/i');
##$telnet->print("pass123");
$telnet->print("1");
$telnet->waitfor('/True RMS current:/i');
@topamp = $telnet->waitfor('/Amps/i');
$telnet->print("logout");

## Get the temp from the bottom RPC ##
$telnet->open ("10.2.4.2") or die("Cannot open");
##$telnet->waitfor('/Enter username>$/i');
##$telnet->print("user1");
##$telnet->waitfor('/Enter password>$/i');
##$telnet->print("pass123");
$telnet->print("1");
$telnet->waitfor('/True RMS current:/i');
@botamp = $telnet->waitfor('/Amps/i');
$telnet->print("logout");
## Print the results ##
print @topamp;
print("\n");
print @botamp;
print("\n");

if (@topamp>= 10) { 
print "Critical! RPC Amp is @topamp";
}
print("\n");

# 2  
Old 06-19-2009
Quote:
Originally Posted by zeekblack
...
Here is the code...
Code:
... 
if (@topamp>= 10) { 
print "Critical! RPC Amp is @topamp";
}
...

Code:
...
if ($topamp[0] >= 10) {
...

tyler_durden
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to compare floating variables , integer value expected?

I am running some commands and I am trying to get an output into a variable. I am having problem when I try to put that value in while loop, it says integer value expected. What's the best way to accomplish this remaining=$(symclone -sid XXX -f Clone_test query | grep MB | awk '{print... (1 Reply)
Discussion started by: rajsan
1 Replies

2. Programming

Floating Point

Anyone help me i cant found the error of floating point if needed, i added the code complete #include <stdio.h> #include <string.h> #include <stdlib.h> #include <ctype.h> typedef struct { int hh; int mm; int ss; char nom; int punt; }cancion; typedef struct... (9 Replies)
Discussion started by: Slasho
9 Replies

3. Shell Programming and Scripting

floating point variables korn shell

Hi I'm not using Korn93 but want to use floating point variable. Is there any solution to do that ? thx for help. ---------- Post updated at 02:28 PM ---------- Previous update was at 12:38 PM ---------- I have the following peace of code: for n in `cat log.January.1.array` do ... (3 Replies)
Discussion started by: presul
3 Replies

4. Shell Programming and Scripting

How to compare floating point numbers in shell script?

How can we compare 2 floating point numbers in SHELL script? (11 Replies)
Discussion started by: dearanik
11 Replies

5. Shell Programming and Scripting

floating point numbers in if

# if > then > echo "1" > else > echo "2" > fi -bash: How can i compare floating point numbers inside statement? (15 Replies)
Discussion started by: proactiveaditya
15 Replies

6. Shell Programming and Scripting

how to compare 2 floating point no.

Hi, Could any one tell me how to compare to floating point no. using test command. As -eq option works on only intergers. i=5.4 if then echo "equal" else echo "not equal" fi here output will be equal even though no. are unequal. Thanks, ravi (1 Reply)
Discussion started by: useless79
1 Replies

7. Programming

Floating point Emulator

what is floating point emulator(FPE)? where and why it is used? (1 Reply)
Discussion started by: pgmfourms
1 Replies

8. Shell Programming and Scripting

How to Compare Floating point / real numbers

Hai, Can you please guide me, to compare the floating point numbers. Eg. If then echo "value1 is grater " fi This code is not working properly when i excuted with floating values or real numbers (13 Replies)
Discussion started by: padarthy
13 Replies

9. Shell Programming and Scripting

floating point addition

hi, :) I have a file like this 10.456 123.567 456.876 234.987 ........ ....... What i want to do is ia have to add all those numbers and put the result in some other file. Any help pls. cheers RRK (8 Replies)
Discussion started by: ravi raj kumar
8 Replies

10. Shell Programming and Scripting

Floating Point Division

Does anyone have a simple way of doing floating point ("fp") division? For example, if I divide 3 by 5, I can get 0.6. The built-in calc (`bc`) will perform fp multiplication, but not division, at least not straight-up (i.e., starting bc and just typing in 3/5). I am trying to do this using... (1 Reply)
Discussion started by: gsatch
1 Replies
Login or Register to Ask a Question