0% found this document useful (0 votes)
18 views11 pages

File Handles and Tests

The document provides an overview of file handles in Perl, explaining their purpose and usage for creating, reading, opening, and closing files. It details the three basic file handles (STDIN, STDOUT, STDERR) and outlines various file opening modes and file test operators to check file properties. Additionally, it lists specific operators to determine file attributes such as readability, writability, and existence.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views11 pages

File Handles and Tests

The document provides an overview of file handles in Perl, explaining their purpose and usage for creating, reading, opening, and closing files. It details the three basic file handles (STDIN, STDOUT, STDERR) and outlines various file opening modes and file test operators to check file properties. Additionally, it lists specific operators to determine file attributes such as readability, writability, and existence.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

FILE HANDLES

AND TEST
PRESENTED BY
SANJANA K K
FILE
• HANDLES
A file handle is a internal Perl structure that
associated with a file name .
• Perl file handles are capable of creating , reading,
opening and closing a file.
• File handles are named like other Perl identifiers , but
they since do not have any prefix character , but use
their own namespace, the convention is to used all
uppercase letters for file handle name.
Three Basic File Handle:
1. STDIN
2. STDOUT
3. STDERR

which represent standard input , standard


output and standard error devices
respectively.
Opening files

SYNTAX:
open(DATA,”<file.txt”);
Here the < sign indicate that file has to
be opened in read only mode. Here,
DATA is the file handle.
Closing file

SYNTAX:
close(DATA);
Here, DATA is the file handle.
Possible values of different mode
SL.NO ENTITIES AND DEFINITION
1 < or r
Read only access
2 > or w
Creates , write and truncates
3 >> or a
Write , appends and creates
4 +< or r+
Reads and writes
5 +> or w+
Reads ,writes, creates and truncates
6 +>> or a+
Reads ,writes, appends and creates
File test
• Before reading from a file or writing to a file,
it is important to check if the file exists and
readable. In order to perform those tasks, we
• use
Perl Perl
file test operators are
file test operators.logical
operators which
return true or false value.
• The file test operator -e accepts a
filename or file handle as an argument.
Perl file test operators:
• -r: check if the file is readable.
• -w: check if the file is writable.
• -x: check if the file is executable.
• -o: check if the file is owned by effective uid.
• -R: check if file is readable.
• -W: check if file is writable.
• -X: check if file is executable.
• -O: check if the file is owned by real uid.
• -e: check if the file exists.
• -z: check if the file is empty.
• -s: check if the file has nonzero size (returns size
in bytes).
• -f: check if the file is a plain file.
• -d: check if the file is a directory.
• -l: check if the file is a symbolic link.
• -p: check if the file is a named pipe (FIFO): or
Filehandle is a pipe.
• -S: check if the file is a socket.
• -b: check if the file is a block special file.
• -c: check if the file is a character special file.
• -t: check if the file handle is opened to a tty.
• -u-heck if the file has setuid bit set.
• -g: check if the file has setgid bit set.
• -k: check if the file has sticky bit set.
• -T: check if the file is an ASCII text file
(heuristic guess).
• -B: check if the file is a “binary” file
(opposite of -T).
THANK
YOU

You might also like