Perl eq运算符
Perl中的 ‘eq ‘运算符是字符串比较运算符之一,用于检查两个字符串的相等。它用于检查其左边的字符串是否与右边的字符串相等。
语法: String1 eq String2
返回: 如果左参数等于右参数,则 返回 1。
例1 :
#!/usr/local/bin/perl
# Initializing Strings
a = "Welcome";b = "Geeks";
# Comparing the strings using eq operator
c =a eq b;
if(c == 1)
{
print"String1 is equal to String2";
}
else
{
print"String1 is not equal to String2";
}
输出。
String1 is not equal to String2
例2 :
#!/usr/local/bin/perl
# Initializing Strings
a = "Geeks";b = "Geeks";
# Comparing the strings using eq operator
c =a eq b;
if(c == 1)
{
print"String1 is equal to String2";
}
else
{
print"String1 is not equal to String2";
}
输出。
String1 is equal to String2