Hi, Isn't eq a string comparison? Try using == instead:
print "String compares\n" if "45" eq "45.0"; # Fails print "Number compares\n" if "45" == "45.0"; # Passes Cheers, Paul -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Paul Rogers Sent: 17 November 2004 02:44 To: Perl-Win32-Users Subject: Re: numeric vs string scalars...difference? Hi Andy, Thanks for your response. For clarification I'm doing equality comparisons. Thus... $x = '45.0'; $y = '45'; if ($x eq $y) {print "values are equal";} ...does not product the desired result (i.e., that they are indeed equal). I used your regex idea to solve the problem (I had some tried some non-regex techniques (namely using unpack) to determine numeric or string status but hit only deadends). I couldn't quite get your regex to work as required so I did some further sloothing and found "Programming Perl" code which more or less mimics the IsNumeric VB function: if ($mytestvar =~ /^-?(\d+\.?\d*|\.\d+)$/) { print "This is a numeric value."; } Thanks, Paul --- ----- Original Message ----- From: Andy Bach To: "Paul Rogers" <[EMAIL PROTECTED]> Sent: Tuesday, November 16, 2004 6:03 PM Subject: Re: numeric vs string scalars...difference? > "45.0" vs "45". > > So should they match (as numbers) or differ (as strings)? > > Assuming the former, you need to do some REs and it'll depend upon your > range of number-like strings. If a simple RE like: > foreach my $data1 ( @first_array ) { > foreach my $data2 ( @second_array ) { > if ( $data1 =~ /^\d*(?:\.\d+)$/ ) { # basic number > print "Matched $data1 == $data2\n" > if ( $data1 == $data2 ) > } elsif ( $data1 eq $data2 ) { > print "Matched $data1 eq $data2\n"; > } > } # foreach $data2 > } # foreach $data1 > > > That's a number as only digits and a possible '.' e.g. 1, 1.0, 0.1 and .1 > > If you don't want the "data2 is not a number" complaint > if ( $data1 =~ /^\d*(?:\.\d+)$/ and > $data2 =~ /^\d*(?:\.\d+)$/ ) { # basic number > > Untested but you get the idea. > > a > > Andy Bach, Sys. Mangler _______________________________________________ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ***************************************************************** Gloucester Research Limited believes the information provided herein is reliable. While every care has been taken to ensure accuracy, the information is furnished to the recipients with no warranty as to the completeness and accuracy of its contents and on condition that any errors or omissions shall not be made the basis for any claim, demand or cause for action. ***************************************************************** _______________________________________________ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs