compare 5% and 40% in perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting compare 5% and 40% in perl
# 1  
Old 05-12-2010
compare 5% and 40% in perl

hi everyone,

how to compare 5% and 40% in perl, which one if bigger?

Thanks
# 2  
Old 05-12-2010
Code:
perl -le'
  print  "$ARGV[0] is ", 
    "$ARGV[0]" > "$ARGV[1]" ? "more" : "less", 
      " than $ARGV[1]"
      '

Code:
% perl -le'
  print  "$ARGV[0] is ",
    "$ARGV[0]" > "$ARGV[1]" ? "more" : "less",
  " than $ARGV[1]"
  ' 5% 40%
5% is less than 40%
% perl -le'
  print  "$ARGV[0] is ",
    "$ARGV[0]" > "$ARGV[1]" ? "more " : "less ",
  "than $ARGV[1]"
  ' 45% 40%
45% is more than 40%

# 3  
Old 05-12-2010
Please share more details on your code usage, OS and perl version. Generally, in Perl you can compare numbers with the usual ==, >, < operators.
# 4  
Old 05-12-2010
If i use below will fail
Code:
#!/usr/bin/perl

if ('5%' < '40%') {
        print "less";
}

or


Code:
#!/usr/bin/perl

if ('5%' lt '40%') {
        print "less";
}

both fail,
# 5  
Old 05-12-2010
What output do you get when you execute the first one?

Code:
#!/usr/bin/perl

if ('5%' < '40%') {
        print "less";
}

# 6  
Old 05-12-2010
Quote:
Originally Posted by radoulov
What output do you get when you execute the first one?

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

if ('5%' < '40%') {
        print "less";
}

Argument "40%" isn't numeric in numeric lt (<) at ./1.pl line 5.
Argument "5%" isn't numeric in numeric lt (<) at ./1.pl line 5.

Smilie
# 7  
Old 05-12-2010
OK,
you could:

- disable warnings for this particular statement (not recommended)
- use something like this:

Code:
#!/usr/bin/perl

use warnings;
use strict;

my ($f, $s) = ('5%', '40%');

chop($f, $s);

if ($f < $s) {
        print "less";
}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare two lists with perl

Hi everybody! I'm trying to delete some elements from a list with two elements on each row agreeing with the elements in another list. Pratically I want a perl script able to take each element of the second list (that is a single column list), compare it with both elements of each row from the... (3 Replies)
Discussion started by: gabrysfe
3 Replies

2. Shell Programming and Scripting

perl: compare two arrays

Hi friends, I want to compare two arrays and find matched one using perl? Also, I want to delete unmatched one. Plz suggest me solution (1 Reply)
Discussion started by: Renesh
1 Replies

3. Shell Programming and Scripting

Perl: compare columns of two files

Hi I have file 1 like this: file 2 is like this: The files are tab separated. I want to search for the first column values of file 1 in the first column of file 2 and merge the 3rd column value of file 2 to the corresponding line on first file. so the desired output is; I tried following... (2 Replies)
Discussion started by: polsum
2 Replies

4. Shell Programming and Scripting

compare two value in array - Perl

Hi, I just wondering if I want to compare previous value to next value if it same count + 1 if not doesn't count how do we compare in Perl? Thank (2 Replies)
Discussion started by: guidely
2 Replies

5. Shell Programming and Scripting

Perl Compare 2 Arrays

Hello, Consider the following 2 arrays: Array1 = qw(Fa0/0 Fa0/1 Fa0/2 Fa0/3); Array1 = qw(Fa0/1 Fa0/2 Fa0/3 Fa0/4); I want to compare the following 2 arrays as follows: Take specific action when elements of Array1 that doesn't exist in Array2 (in my example: Fa0/0). Take another... (4 Replies)
Discussion started by: ahmed_zaher
4 Replies

6. Shell Programming and Scripting

Compare arrays (perl)

Hi, my first post here! Description of my problem: I have one txt-file with six rows and each row contains seven numbers seperated with whitespaces. I want to: Compare one array with seven numbers with each row of numbers in the txt-file. I have managed to compare one array with... (6 Replies)
Discussion started by: mjoh
6 Replies

7. Shell Programming and Scripting

compare 2 arrays in perl

Hi Im supposed to compare lines in a file : KB0005 1019 T IFVATVPVI 0.691 PKC YES KB0005 1036 T YFLQTSQQL 0.785 PKC YES KB0005 1037 S FLQTSQQLK 0.585 DNAPK YES KB0005 1045 S KQLESEGRS 0.669 PKC YES KB0005 1045 S KQLESEGRS 0.880 unsp YES KB204320 1019 T IFVATVPVI 0.699 PKC YES ... (7 Replies)
Discussion started by: karla
7 Replies

8. Shell Programming and Scripting

Compare arrays in perl

Hello, Let's say that we have the two following arrays @array1= @array2= Is there any easy way to compare these two arrays and print the values that exist in array1 and not in array2 and the values that exist in array2 and not in array1? Regards, Chriss_58 (3 Replies)
Discussion started by: chriss_58
3 Replies

9. Shell Programming and Scripting

Perl - Compare 2 Arrays

Hi all, I have the following script where the contents of file1 and file2 would be something like this: file1: 56790,0,0,100998765 89756,0,0,100567876 867645,1,3,678777654 file2: 56790,0,0,100998765 65776,0,0,4766457890 +5896,0,0,675489876 What I then want to do is check if... (4 Replies)
Discussion started by: Donkey25
4 Replies

10. Shell Programming and Scripting

File Compare in PERL

I need to look at a log file every half hour or so to make sure that some activity is going on there. I thought I would write a quick PERL script that would copy the current log file to the temp directory, compare it to the previous log file (from 30 minutes ago) and exit with an error status if... (1 Reply)
Discussion started by: Cbish68
1 Replies
Login or Register to Ask a Question