Skip to content
Related Articles
Open in App
Not now

Related Articles

Perl | getc Function

Improve Article
Save Article
  • Last Updated : 07 May, 2019
Improve Article
Save Article

getc() function in Perl is used to read the next character from the file whose File Handle is passed to it as argument. If no FileHandle is passed then it takes one character as input from the user.

Syntax: getc(FileHandle)

FileHandle: of the file to be read

Returns: the character read from the file or undef on end of file

Example 1:

# 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 


Example 2:

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


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!