Exercise 5.10: Difference between revisions

From Earlham CS Department
Jump to navigation Jump to search
Erika (talk | contribs)
New page: Return to Week 2 <br> Exercise 5.10 in <i>Beginning Perl for Bioinformatics</i></b> <pre> </pre>
 
Erika (talk | contribs)
No edit summary
 
Line 4: Line 4:


<pre>
<pre>
#!/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;


</pre>
</pre>

Latest revision as of 02:10, 29 September 2009

Return to Week 2
Exercise 5.10 in Beginning Perl for Bioinformatics

#!/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;