Perl Tutorials -Part 76- Reading user input from the command

Posted on June 7, 2010. Filed under: Perl Tutorials |






do

{

$fileName = ”;

do

{

if ($fileName ne ”)

{

print “Sorry – invalid filename. \n”;

}

# prompt the user for the file

print “which file?”;

$fileName = <>;

chomp $fileName;

}

while (!open WORKING, $fileName);

# pull in the contents of the file

@stats = stat $fileName;

read WORKING, $contents, $stats[7];

# show the contents to the user

print $contents;

print “\nAnother file (y/n)?”;

$another = <>;

}

while($another !~ /[nN]/);

Advertisements

Make a Comment

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

Liked it here?
Why not try sites on the blogroll...

%d bloggers like this: