#!perl
# Simple Perl script for partial testing of a Win32 perl install.
# This script tests some of Perl's standard I/O and file funcions.
# You must type in the word 'yes' or 'YES' (without quotes), or
# the new file will NOT be created and the program quits.
$wfile = "Test4.tmp";
print "\n\n To create a new text file called: $wfile ,\n";
print " enter the word 'yes' (or 'YES') here: ";
$ans = ; # Whatever you typed in is stored in $ans.
chop($ans); # This takes off the last character; a CR/LF.
if ($ans eq 'yes' || $ans eq 'YES') { open (WTEST, ">$wfile"); }
else { die("\n You didn't enter a 'yes' so we quit"); }
# Here we WRITE a a couple lines of data into the file we created:
print WTEST " This file was created by perl.exe when you ran";
print WTEST " the 'test4.pl'\n perl script. The program asked ";
close WTEST;
# If we can OPEN the file for READ-ing, it must be there.
open (CTEST, "<$wfile") || die("\n\n Error: Couldn't open file");
close CTEST;
print "\n The file '$wfile' was created OK ... ";
# Here we add (APPEND) some more data to the file we created.
# You are asked to add a line of your own from the keyboard:
open (ATEST, ">>$wfile");
print ATEST "if it should delete the file\n $wfile ";
print ATEST "for you before it finished running.\n";
print ATEST " You added the following line to the file:\n ";
print "\n\n Enter a line of data to add to the test file:\n ";
$line5 = ;
print ATEST $line5;
close ATEST;
# Here we open the file again, read its contents and print it out:
open (RTEST, "<$wfile") || die("\n\n Can't find file");
@wfile = ;
print "\n The temporary text file, $wfile, contains these lines:\n\n";
print @wfile;
close RTEST;
# This section asks if it should delete the temporary file that we
# created. If you don't answer 'yes' it tells you what happened and
# suggests you use DEL at a DOS prompt to delete the file instead.
print "\n\n Should I delete the file '$wfile' (Enter a 'yes')? ";
$ans2 = ;
chop($ans2);
if ($ans2 eq 'yes' || $ans2 eq 'YES') {unlink "$wfile";
open (TTEST, "<$wfile") || print("\n Temporary file $wfile deleted.\n");}
else { print("\n You did NOT enter a 'yes' ");
print ("\n If you want to delete '$wfile' now, do the following.\n");
print (" At the DOS command prompt, type: DEL $wfile \n"); }
exit; # Usual term for showing humans the end of your script.
# This script, test4.pl, Copyright(C)1999 by The Starman.
# http://www.geocities.com/Athens/6939/index.html
               (
geocities.com/thestarman3)