dmo.ca/ blog/ Bad Perl

One of the RSS feeds I read regularly is of newly uploaded CPAN modules. Today, I saw one worthy of The Daily WTF: File::ReadSimple.

It's got such wonderful gems as:

sub file_read {
open ( FILEREAD, "@_" ) || die "File not found" ;
while ( readline *FILEREAD )
{
print $_;
}  
close ( FILEREAD );  
}

(and yes, it was formatted exactly like that). This is supposed to make it "easy" for non-programmers to do something like:

#!/usr/bin/perl
use IO::File;
my $fh = IO::File->new('1.txt');
print <$fh>;

by using:

#!/usr/bin/perl
use File::ReadSimple;
file_read("1.txt");

instead. Unfortunately, it uses all sorts of bad programming practices, and really does nothing good for the Perl newbie. Someone unfamiliar with Perl would do better to read the perl manpages (like 'man IO::File', 'man perlopentut' or even just 'perldoc -f open'). Or, maybe (gasp!) use a better tool for that particular job, like bash:

#!/bin/sh
cat 1.txt

After all, if they're such a non-programmer that they can't do basic Perl file IO, what chance do they have of doing anything else useful in Perl?

This is unfortunately one of the things wrong with CPAN -- just about anyone can create a module and upload it for the world. There's really no solution for this. While it would be nice to keep completely useless, misleading, or bad code off of CPAN, any process that could do so would end up wasting countless person-hours in political wanking, and likely end up blocking or delaying useful things from being posted.