Perl Notes Part 2 – Files



Standard Files





To read Input from Keyboard


input = <STDIN>;


To read input from keyboard until Ctrl+D or Ctrl+Z is pressed

while (<STDIN>){    #input read to $_




To Remove the newline character at the end of line

$input = chomp(<STDIN>);


Diamond operator <> when no input provides look into ARGV array for the stream.

Read Multiple Files at a time


@ARGV = (“”, “”);

while (<>) {





File Test Operators


Perl has many operators that you can use to test different aspects of a file. For example, you can use the -e operator to ensure that a file exists before deleting it. Or you can check that a file can be written to before appending to it. By checking the feasibility of the impending file operation, you can reduce the number of errors that you program will encounter



If file exists


If file is zeo bytes


If file is readable


If file can be update/written


If file is an executable File


About wikihead

A Seeker. Information Security Professional, Pursuing Life with Ayurveda.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s