Feeds:
Posts
Comments

Posts Tagged ‘Perl’

Here’s a little script I wrote to look up words whilst reading a book or browsing the web. It uses the Aonaware web-service to get the definitions and prints them out to the console. And if you misspell a word it will offer some suggestions.

You will need to install the LWP::Simple and XML::XPath modules from CPAN to get it to work, but other than that it should be clean sailing.

If you have comments, bugs to moan about or feature requests then let me know 🙂

Advertisements

Read Full Post »

Perl Nightmare

During my job last summer, I stumbled across this idiosyncracy in Perl. See if you can spot the bug and discover a solution.

#!/usr/bin/perl

use strict;
use warnings;

use constant win => 1;

my %foo = ();
$foo{win} = "Winner!\n";

printHashIfExists(win, \%foo);

sub printHashIfExists
{
  my ($key, $hashRef) = @_;

  if ( exists $hashRef->{$key} )
  {
    print $hashRef->{$key}
  }
  else
  {
    print "loser!\n";
  }
}

Read Full Post »