Please help me to understand one strange problem in equality of strings. This is the code I'm talking about:
my $test=undef;
foreach my $List (@o_descrL) {
if (!($test)) {
$test = defined($o_noreg)
? $descr_d eq $List
: $descr_d =~ /$List/i;
printf("$descr_d = $List\t\t==> $test\n");
}
}
Unfortunately I didn't write it but I have to understand it. $List
is always "SQL Server (C4)", $descr_d
is changing according to actual item in array. Part of the printed output is here:
Power = SQL Server (C4) ==>
SQL Server (C4) = SQL Server (C4) ==>
SNMP Service = SQL Server (C4) ==>
Network Connections = SQL Server (C4) ==>
As you can see, strings in the second line of the output are equal. So why isn't $test
true?
EDIT: I've printed some more output and found out that when $descr_d eq $List
, it equals, but not if $descr_d =~ $List
. Could you please explain what is actually putting to the $test
variable? I don't understand what does defined() ? :
mean in here.
EDIT2: For a string "SQL Server Agent" the script works just fine, there is a problem only when (C4) is attached. Quite strange, isn't it?