I have never had any problems in dealing with ‘eq’ or ‘==’ until today. Below is a piece of my codes:
The following is the output of a test run:
I certainly understand the error messages in red and do expect them shown up. The things I don’t understand are:
1) Why does the error about line 25 show up twice?
2) Why do both numeric matches still succeed?
3) I did expect the codes in blue should be executed. Why weren’t they?
Thank you very much for your help!!
Code:
#! /usr/bin/perl
use strict;
use warnings;
my $hardcodedKernelInDouble = "2.6.5.7-244";
my $hardcodedKernelInSingle = '2.6.5.7-244';
my $kernelRealtime = `uname -r`;
chomp($kernelRealtime);
$kernelRealtime =~ s/^\D+//g;
$kernelRealtime =~ s/\D+$//g;
print "Real Time Kernel: #$kernelRealtime#\n";
if($kernelRealtime eq $hardcodedKernelInDouble) {
[COLOR=blue][b]print "String match double: #$kernelRealtime#\n";[/b][/color]
}
else {
print "String Not match double. \$kernelRealtime = #$kernelRealtime#, \$hardcodedKernelInDouble = #$hardcodedKernelInDouble#\n";
}
if($kernelRealtime eq $hardcodedKernelInSingle) {
[COLOR=blue][b]print "String match single: #$kernelRealtime#\n";[/b][/color]
}
else {
print "String Not match single. \$kernelRealtime = #$kernelRealtime#, \$hardcodedKernelInSingle = #$hardcodedKernelInSingle#\n";
}
if($kernelRealtime == $hardcodedKernelInDouble) { [b]# line 25[/b]
print "Numeric match double: #$kernelRealtime#\n";
}
else {
print "Numeric Not match double. \$kernelRealtime = #$kernelRealtime#, \$hardcodedKernelInDouble = #$hardcodedKernelInDouble#\n";
}
if($kernelRealtime == $hardcodedKernelInSingle) { [b]# line 31[/b]
print "Numeric match single: #$kernelRealtime#\n";
}
else {
print "Numeric Not match single. \$kernelRealtime = #$kernelRealtime#, \$hardcodedKernelInSingle = #$hardcodedKernelInSingle#\n";
}
The following is the output of a test run:
Code:
% uname -r
2.6.5-7.244-default
% ./test.pl
Real Time Kernel: #2.6.5-7.244#
String Not match double. $kernelRealtime = #2.6.5-7.244#, $hardcodedKernelInDouble = #2.6.5.7-244#
String Not match single. $kernelRealtime = #2.6.5-7.244#, $hardcodedKernelInSingle = #2.6.5.7-244#
[COLOR=red]Argument "2.6.5.7-244" isn't numeric in numeric eq (==) at ./strEqual.pl line 25.
Argument "2.6.5-7.244" isn't numeric in numeric eq (==) at ./strEqual.pl line 25.[/color]
[b]Numeric match double: #2.6.5-7.244#[/b]
[COLOR=red]Argument "2.6.5.7-244" isn't numeric in numeric eq (==) at ./strEqual.pl line 31.[/color]
[b]Numeric match single: #2.6.5-7.244#[/b]
I certainly understand the error messages in red and do expect them shown up. The things I don’t understand are:
1) Why does the error about line 25 show up twice?
2) Why do both numeric matches still succeed?
3) I did expect the codes in blue should be executed. Why weren’t they?
Thank you very much for your help!!