當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


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


相關用法


注:本文由純淨天空篩選整理自Code_Mech大神的英文原創作品 Perl | eq operator。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。