Archive for June, 2017

Practice

June 6, 2017

So, I’ve been utterly terrible about updating this blog.  I’ve also been pretty darned quiet in the Perl 6 world, I fear.

That doesn’t mean I’ve abandoned Perl 6, though.  Actually, it’s been a very exciting time for me, because I’m finally actually using Perl 6 productively on a very regular basis.  Most weeks see me write two or three helpful little scripts, both for work and pleasure.  As an example, here’s yesterday’s:


my $proc-rsync = run 'rsync', '-trvL', '--delete', 'colomon@melissa:s3/Music/TunesToLearn', '/Users/colomon/sol/temp/', :out, :err;
$proc-rsync.out.slurp;

my $proc-ls = run 'ls', '/Users/colomon/sol/temp/TunesToLearn', :out;

my @files = $proc-ls.out.slurp.lines;

for @files.pick(*) -> $file {
    say "Playing $file";
    my $proc-afplay = run 'afplay', '/Users/colomon/sol/temp/TunesToLearn/' ~ $file, :out;
    $proc-afplay.out.slurp: :close; # let the track finish playing before moving on
}

What’s this do?  The first two lines rsync the contents of my “tunes to learn” directory on my server to my laptop.  This directory is a set of MP3 files containing tunes that I would like to learn to play.

The next two lines get the list of those files and stashes them in the @files array.

Finally the for loop shuffles that list and goes through it calling OS X’s afplay command to play each file.  The $proc-afplay.out.slurp is extremely important — without that, the script tried to play all the files at once!  afplay seemed fine with that, but it was quite painful to hear.

This script isn’t exactly rocket science, but it seems to get the job done quite nicely, with a minimum of programming effort.