Perl Notes Part 2 – Files

Files

 

Standard Files

STDIN

STDOUT

STDERR

 

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 $_

        print();

}

 

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 = (“09lst01.pl”, “09lst02.pl”);

while (<>) {

print();

}

 

 

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

   

-e

If file exists

-z

If file is zeo bytes

-r

If file is readable

-w

If file can be update/written

-x

If file is an executable File

   
   
Advertisements

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:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

w

Connecting to %s