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 Uma Mahesh

A Creator/Equilizer. Creator/Equalizers are catalysts for positive, well-organized change. They never settle for the status quo. Instead, they see the opportunity for innovation in the processes that others have long taken for granted. They respect what's already operating, but they can't help but want to improve upon it. Their special combination provides innovation tempered with profound logic. They have incredible discernment. Should their efforts fail, they are unhesitating in accepting responsibility. They don't wallow in self-pity but rather see these missed attempts as critical steps on the path to success.
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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s