prad_intel has asked for the wisdom of the Perl Monks concerning the following question:

Hi All,

I am stuck up with a genuine problem of comparing a string which contains alpha-numeric values.

Can any monk point out how must i proceed in comparing it.

prad

Replies are listed 'Best First'.
Re: alpha numeric comparision
by nobull (Friar) on Jan 28, 2005 at 12:57 UTC

    In Perl most simple string comarison operations you could think of are done using the string comparison operators or the regex match operator.

    But you say you have a genuine problem. And if it could be trivially solved using the string comparison operators or the regex match operator it would not be a genuine problem.

    Perhaps you should try describing your problem.

Re: alpha numeric comparision
by tphyahoo (Vicar) on Jan 28, 2005 at 13:02 UTC
    #comparison.pl use warnings; use strict; if ("1a" lt "2b") { print "1a is less than 2b."; } if ("2b" gt "1a") { print "2b is greater than 1a."; }
Re: alpha numeric comparision
by prad_intel (Monk) on Jan 28, 2005 at 12:52 UTC
    Hi, The temp_var string can start with either an alphabet or a number but the whole string is alpha numeric.

    if($temp_var1 == $temp_var2 and $temp_var2 == $temp_var3) {printf LOG"1";} if($temp_var2 != $temp_var1 and $temp_var3 == $temp_var2) {printf LOG"2";} if($temp_var2 eq $null and $temp_var3 eq $null) + {printf LOG"3";} if($temp_var3 == $temp_var1 and $temp_var2 eq $null) {printf LOG"4";} if($temp_var1 != $temp_var2 and $temp_var3 eq $null) {printf LOG"6";} if($temp_var2 != $temp_var1 and $temp_var3 != $temp_var1) {printf LOG"5";} if($temp_var1 == $temp_var2 and $temp_var3 != $temp_var1) {printf LOG"5";} if($temp_var2 == $temp_var1 and $temp_var3 eq $null) {printf LOG"5";}

    Prad
      There is no clue there as to what you are trying to achieve.
        I have 3 variables,I want to compare those 3 based on a particular logic

        All i want now is the variables are alpha numeric, i tried regex but i am unable to achieve the above

        Hope i get a guiding light.

        Prad
Re: alpha numeric comparision
by samizdat (Vicar) on Jan 28, 2005 at 13:38 UTC
    I agree with nobull. Whazzup? HOW do you want to compare them? Alphabetically greater than? Numerically greater than?
    Alpha: if ( $temp_var1 gt $tempvar2 ) { print "gt\n"; } Numerically: $_ = $temp_var1; tr/a-zA-Z//g; $tnum1 = $_; $_ = $temp_var2; tr/a-zA-Z//g; $tnum2 = $_; if ( $tnum1 > $tnum2 ) { print "gt\n"; }