Tuesday May 15, 2007

Manageable Music

I download a good bit of music from eMusic, but without the benefit of their download manager [1], so all of the mp3's I pull from eMusic tend to end up in the same directory, which, IMHO, is not really that useful. Anyway there are a probably one hundred and one scripts and programs to sort your mp3's, but heres mine in case it might be of use to someone.... You'll need to download MP3::Tag for Perl to extract out the relevant info from your mp3 files.

[fintanr@prometheus fintanr] $ mymp3sorter -h

Usage : mymp3sorter [-i input dir][-o output dir][-v][-h]
Where : -i directory containing the mp3s you wish to sort
        -d directory to place sorted mp3s and directory structure
        -v verbose output
        -h display this help

You can download the script here. Happy sorting.

[1] I could use the now unsupported Linux downloader in a brandz zone if I was so inclined, but lifes just too short.

Sunday Apr 17, 2005


One of the more common complaints that you hear from people regarding perl on Solaris is that you need the Sun CC compiler to compile modules. This was addressed quite some time ago, but as I generally have cc available I never really notice the issue. Or I didn't until about ten minutes ago.

I need a local copy of Expect.pm for some stuff I'm working on, so I went off to compile up IO::Tty which is required by the Expect.pm module. And as I typed make I get the following.

/usr/bin/perl /usr/perl5/5.8.4/lib/ExtUtils/xsubpp  -typemap 
/usr/perl5/5.8.4/lib/ExtUtils/typemap  Tty.xs > Tty.xsc && mv Tty.xsc Tty.c
cc -c    -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_TS_ERRNO -xO3 -xspace -xildoff    
-DVERSION=\\"1.02\\"  -DXS_VERSION=\\"1.02\\" -KPIC 
"-I/usr/perl5/5.8.4/lib/i86pc-solaris-64int/CORE"  -DHAVE_DEV_PTMX -DHAVE_GRANTPT 
cc: unrecognized option `-KPIC'
cc: language ildoff not recognized
cc: Tty.c: linker input file unused because linking not done
Running Mkbootstrap for IO::Tty ()
chmod 644 Tty.bs
rm -f blib/arch/auto/IO/Tty/Tty.so
LD_RUN_PATH="" cc  -G Tty.o  -o blib/arch/auto/IO/Tty/Tty.so
cc: Tty.o: No such file or directory
cc: no input files
\*\*\* Error code 1
make: Fatal error: Command failed for target `blib/arch/auto/IO/Tty/Tty.so'
Basically whats happened here is that perl is compiled with the Sun compilers, and I'm trying to compile this module with gcc from /usr/sfw/bin. And perl doesn't like this (you can go take a look at /usr/perl5/5.8.4/lib/i86pc-solaris-64int/Config.pm for all the gory detail).

Anyway the work around is to use a handy little script bundled in Solaris called perlgcc, so rather than your normal perl Makefile.PL; make; make test; make install you do

/usr/perl5/5.8.4/bin/perlgcc Makefile.PL; make
and away you go. As an aside -KPIC is an option for generating position idependent code, and is dealt with in a lot more detail in the linkers and libraries documentation.

Tuesday Mar 01, 2005

Tarballs and CGI scripts

One of the things that a performance group tends to generate is a huge amount of data, and while we make all of this available online, sometimes people like to just grab the data and analyse it later. So in order to make it easier for them to do this (and the fact that it is definately needed to finish up the current project I'm working on) I wrote up a quick cgi script earlier on today that automagically generates tarballs from a cgi script. It may be of use to some folks.

First a quick explanation about using stdout for output, in tar you use the - option, while in compress you just don't give it any options. So to create a compressed tarball on standard out for the directory your in you would do the following.

tar -cf \* - | compress
Obviously this isn't really much use unless you like your terminal beeping at you a lot (personally I don't, even when listening to techno[1] ;) ). So lets make a little bit more use of these features.

Our perl script does the following, first up it creates our cgi header, we need to set the mime type correctly (or semi correctly in this case, CGI.pm has, I belive, a limitation about what it will allow you to use if you wish to give a binary file a name and force its download, but I could be wrong on this). So in this case the mime type is set to being "application/octet-stream" while we use the -attachment attribute to give a file name.

Next its just a matter of outputting the actual tarfile, so we switch into binary mode for the output, and then read in the output we are getting from standard out, buffering it to make sure we don't run into any strangeness, and then print out each buffer. And thats it. The relevant snippets of code are below for your perusal.


use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
use constant BUFFER_SIZE => 4_096;
use strict;

my $buffer = "";
my $tar = "/usr/bin/tar";
my $compress = "/usr/bin/compress";

my $cgi = new CGI;
my $dir = $cgi->param("dir");

print $cgi->header(-type => "application/octet-stream", 
		   -expires => "-1d", 
		   -attachment => "$dir.tar.Z" );

binmode STDOUT;
local \*TARBALL;

open(TARBALL, "$tar -cf - \* | $compress |");
while ( read( TARBALL, $buffer, BUFFER_SIZE ) ) {
    print $buffer;
close TARBALL;

[1] Miss Kittin's Live at I Love Techno is the current album of choice... more electro than techno though, which is a good thing

Sunday Feb 27, 2005

Testing DB Interactions with DBD::Mock

Nice article over on perl.com demonstrating how to use DBD::Mock for testing Perl code that interacts with databases. Full article is here.

Monday Jul 19, 2004

Profiling Perl

Very interesting article on Profiling Perl over at perl.com. Well worth a read.




« July 2016