0% found this document useful (0 votes)
5 views10 pages

Test in Perl

The document provides an overview of file handling in Perl, detailing the use of FileHandles to manage external files, including standard input, output, and error devices. It explains various file modes for opening files, such as read-only, write, and append, along with functions like chop() and chomp() for string manipulation. Additionally, it introduces file test operators that check file properties like existence, readability, and type.
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)
5 views10 pages

Test in Perl

The document provides an overview of file handling in Perl, detailing the use of FileHandles to manage external files, including standard input, output, and error devices. It explains various file modes for opening files, such as read-only, write, and append, along with functions like chop() and chomp() for string manipulation. Additionally, it introduces file test operators that check file properties like existence, readability, and type.
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/ 10

FILE HANDLES

AND TEXT IN
PERL
By
Vishnupriya v v
FileHandle
Associates a name to an external
file,
▸ can be used until the end of the
program or until the FileHandle is closed
Introduction  It is like a connection to modify the contents of an
external file
 Three basic FileHandles
 STDIN- Standard Input device
 STDOUT- Standard Output device
 STDERR-Standard Error device
Basic File Handles
Reading the information from standard input file
and Output to Standard Output
Basic file
handles print “What is your name?\n”;
$name = <STDIN>;
print “Hello $name\n”;
open(FileHandle, Mode, FileName);
File
Handling Parameters:

open and FileHandle- The reference to the file, used within the
program.
close Mode- Mode in which a file is to be opened.
FileName- The name of the file to be opened.
 Expression-Mode and FileName clubbed together.
 “<” Open(DATA,
Read Only Mode
“<file.txt”);
Reads and Writes but
 “+<“ open(DATA,
does NOT Create
“+<file.txt”);
Different Creates file (if
open(DATA,
modes in “>” necessary), Clears the
contents of the File and
“>file.txt”);

file “>>”
Writes to it
open(DATA,
“>>file.txt”);
handling Creates file (if
necessary), Appends to
open (DATA,
“+>” the File
“+>file.txt”);
Creates file (if
open(DATA,”+>
 “+>>” necessary), Clears, >file.txt”);
Reads and Writes

Creates file (if


necessary), Reads and
removes last character from a string
regardless of what that character is.
 It returns the chopped character from
the string.

CHOP() Sa = "AEIOU";chop
($a);print "Sa\n";

#it will return ΑΕΙΟ.

$a = "AEIOU";
$b = chop($a);

#it will return U


Chomp()
removes any new line character from the end of the
string.
It returns number of characters removed from the string.
$a = “AEIOU”;
chomp($a);
CHOMP() print “$a\n”;
ΑΕΙΟU
$b = chomp($a); print “$b\n”;
0
$a = “AEIOU\n”;
$b = chomp($a);
print “$b\n”;
 #returns 1, number of char moved.
File Test Operators in Perl are the logical
operators which return True or False values

-d. Check whether file is a directory.


-e. Check whether file exists or not.
-r Check whether file is readable or not.
Perl file test -w. Check if file is writable or not.

operators -f. Check type of file whether it is regular,


symbolic link or type of file.

Example-
Another perl
test
operator
Perl THANKYOU

You might also like