Web | This Site

Perl Home
PERL Functions
© 2011 TutorialsPoint.COM

| Home |  | References |  | About TP |  | Advertising

# PERL readline Function

## Syntax

readline EXPR

## Definition and Usage

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 <>.

## Return Value

- In a scalar context, only one line is returned

- In a list context, a list of line) up to end-of-file is returned

## Example

Try out following example:

    #!/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);

It will produce following results:

    # /etc/services:
    # $Id: services,v 1.33 2003/03/14 16:41:47 notting Exp $

Advertisement

Online Image Processing

Indian Baby Names