珀尔 | getc函数
Perl 中的getc()函数用于从文件中读取下一个字符,文件句柄作为参数传递给它。如果没有传递 FileHandle,则它将一个字符作为用户的输入。
Syntax: getc(FileHandle)
Parameter:
FileHandle: of the file to be read
Returns: the character read from the file or undef on end of file
示例 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";
输出: