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 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:

WordPress.com Logo

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