📜  珀尔 | getc函数

📅  最后修改于: 2022-05-13 01:54:31.954000             🧑  作者: Mango

珀尔 | getc函数

Perl 中的getc()函数用于从文件中读取下一个字符,文件句柄作为参数传递给它。如果没有传递 FileHandle,则它将一个字符作为用户的输入。

示例 1:

#!/usr/bin/perl 
    
# Opening a File in Read-only mode 
open(fh, "<", "File_to_be_read.txt"); 
    
# Reading next character from the file
$ch = getc(fh)
  
# Printing the read character
print"Character read from the file is $ch";
  
# Closing the File 
close(fh); 

输出:

示例 2:

#!/usr/bin/perl 
  
# Value to be entered by the user
$ch = getc(STDIN);
  
# Printing the entered value
print"Value entered: $ch";

输出: