November 2016 Archives

Backticks and tests in Perl 6

Perl was created for systems administration, and Perl 6 has all the chops you've come to expect from the brand. Here I needed to use MD5 checksums from my collaborator to verify that I downloaded all their data without errors. Each data "$file" has an accompanying "$file.md5" that looks like this:

$ cat HOT232_1_0770m/prodigal.gff.md5
a36e4adfaa62cc4adb8cea44c4f7825f  HOT232_1_0770m/prodigal.gff

So I need to read the contents of this file, get just the first field, then execute my local "md5" (or "md5sum") program on the file without the ".md5" extension and determine …

Movie file reader

Last night I finally got to see The Martian. It was a fun movie, and it seems much of the science was solid. One thing that filmmakers still like to do is have computers spit out messages one-character-at-a-time as if they were arriving like telegrams. If you would like to read a file like this, I present the movie-file-reader. First, my very long-hand version:

#!/usr/bin/env perl6

sub MAIN (Str $file) {
for $file.IO.lines(:chomp(False)) -> $line {
for $line.comb -> $letter {
print $letter;
my $pause = do given $le…

Finding cheaters with k-mers

This semester I'm teaching Perl 6 to beginners. On a recent homework, student A came to see me for help, so I pretty much wrote the script (if you come for help, you get help!). With every assignment, I provide a "test.pl6" script that lets the students know if they will pass. I stress that they don't need to code for edge cases -- just look to pass the test suite. Well, two students, B and C, copied student A, changed a variable name, and submitted.

If I had only checked for passing tests, I wouldn't have noticed, but I like to see how different students try to solve the problem…

Bouncy balls with Perl 6

I've never written games before, but I previously posted a Hangman that I thought was fun. I love the examples of forest fire and Game of Life and wanted to create something like those. I originally wanted to create Pong but decided to try a simple ball that bounces off the walls of a container.

I showed this to my daughter, and she asked if there could be more than one ball, so I add…

About Ken Youens-Clark

user-pic I work for Dr. Bonnie Hurwitz at the University of Arizona where I use Perl quite a bit in bioinformatics and metagenomics. I am also trying to write a book at Comments welcome.