Perl readline Function
Description
This function reads a line from the filehandle referred to by EXPR, returning the result. If you want to use a FILEHANDLE directly, it must be passed as a typeglob.
Simply readline function is equvivalent to <>.
Syntax
Following is the simple syntax for this function −
readline EXPR
Return Value
This function returns only one line in a scalar context and in a list context, a list of line up to end-of-file is returned
Example
Following is the example code showing its basic usage −
#!/usr/bin/perl -w
my($buffer) = "";
open(FILE, "/etc/services") or
die("Error reading file, stopped");
$buffer = <FILE>;
print("$buffer");
$buffer = readline( *FILE );
print("$buffer");
close(FILE);
When above code is executed, it produces the following result −
# /etc/services: # $Id: services,v 1.33 2003/03/14 16:41:47 notting Exp $
perl_function_references.htm
Advertisements