打印運算符珀爾用於打印作為參數傳遞給它的列表中表達式的值。打印運算符打印作為參數傳遞給它的任何內容,無論它是字符串、數字、變量還是其他內容。 Double-quotes(“”) 用作該運算符的分隔符。
用法: print “”; or print(); or print(” “);
返回:
0 on failure and 1 on success.
示例 1:
珀爾
#!/usr/bin/perl -w
# Defining a string
$string = "Geeks For Geeks";
# Defining an array of Integers
@array = (10, 20, 30, 40, 50, 60);
# Searching a pattern in the string
# using index() function
$index = index ($string, 'or');
# Printing the position of matched pattern
print "Position of 'or' in the string $index\n";
# Printing the defined array
print "Array of Integers is @array\n";
輸出:
Position of 'or' in the string 7 Array of Integers is 10 20 30 40 50 60
示例 2:
珀爾
#!/usr/bin/perl -w
# Defining a string
$string = "Welcome to GFG";
# Defining an array of integers
@array = (-10, 20, 15, -40, 45, -60);
# Searching a pattern in the string
# using index() function
$index = index($string, 'o G');
# Printing the position of matched pattern
print "Position of 'o G' in the string $index\n";
# Printing the defined array
print "Array of Integers @array\n";
輸出:
Position of 'o G' in the string 9 Array of Integers -10 20 15 -40 45 -60
我們還可以使用像 print() 這樣帶大括號的 print 來打印一些東西,它的作用與上麵相同,這是針對那些來自其他語言的開發人員,其中有 print() 而不是打印“”。
珀爾
#!/usr/bin/perl
# your code here
#!/usr/bin/perl -w
# Defining a string
$string = "Welcome to GFG";
# Defining an array of integers
@array = (-10, 20, 15, -40, 45, -60);
# Searching a pattern in the string
# using index() function
$index = index($string, 'o G');
# Printing the position of matched pattern
print("Position of 'o G' in the string $index\n");
# Printing the defined array
print("Array of Integers @array\n");
輸出 -
Time Complexity - O(1). Space Complexity - O(1).
相關用法
- Perl print用法及代碼示例
- Perl printf用法及代碼示例
- Perl print() and say()用法及代碼示例
- Perl prototype用法及代碼示例
- Perl prototype()用法及代碼示例
- Perl pack用法及代碼示例
- Perl pipe用法及代碼示例
- Perl pop用法及代碼示例
- Perl pos用法及代碼示例
- Perl push用法及代碼示例
- Perl push()用法及代碼示例
- Perl abs用法及代碼示例
- Perl alarm用法及代碼示例
- Perl bless用法及代碼示例
- Perl caller用法及代碼示例
- Perl chmod用法及代碼示例
- Perl chomp用法及代碼示例
- Perl chop用法及代碼示例
- Perl chr用法及代碼示例
- Perl continue用法及代碼示例
- Perl crypt用法及代碼示例
- Perl dbmclose用法及代碼示例
- Perl dbmopen用法及代碼示例
- Perl defined用法及代碼示例
- Perl dump用法及代碼示例
注:本文由純淨天空篩選整理自Code_Mech大神的英文原創作品 Perl | print operator。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。