Perl | getc Function
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)
Parameter:
FileHandle: of the file to be readReturns: the character read from the file or undef on end of file
Example 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); |
chevron_right
filter_none
Output:

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

Recommended Posts:
- Perl | ord() Function
- Perl | hex Function
- Perl | chr() Function
- Perl | oct() Function
- Perl | abs() function
- Perl | sin() Function
- Perl | cos() Function
- Perl | exp Function
- Perl | int() function
- Perl | uc() Function
- Perl | each() Function
- Perl | tell() Function
- Perl | log() Function
- Perl | unshift() Function
- Perl | sqrt() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



