Exercise 5.10

From Earlham Cluster Department

Jump to: navigation, search

Return to Week 2
Exercise 5.10 in Beginning Perl for Bioinformatics</b>

#!/usr/bin/perl
use warnings;
use strict;

#Erika Phelps
#28 Sept 2009
#Exercise 5.10

#Pseudocode:

#Use the script from exercise5-3 to generate information to write to a file.
#Write file.
#print the file.
#unlink the file (delete the temporary file)

#Bring in code from exercise5-3
my $count = 0;

#Initialize the loop

while ($count < 101) {

    $count++;

   # print "$count\n";
}

#Also write the results to a file called "temporary"

my $outputfile = "temporary";

unless ( open(TEMPORARY, ">$outputfile") ) {

    print "Cannot open file \"$outputfile\" to write to.\n\n";
    exit;
}

#Print contents of temporary file
print TEMPORARY "$count\n";

#Close the file.
close (TEMPORARY);

#Unlink the file (delete it)

unlink "TEMPORARY";

#Check to see if the file was deleted.

unless ( open(TEMPORARY, ">$outputfile") ) {

    print "The file \"$outputfile\" has been successfuly deleted.\n\n";
    exit;
}

#Exit the program
exit;

Personal tools
Namespaces
Variants
Actions
websites
wiki
this semester
Toolbox