Feeds:
Posts
Comments

Posts Tagged ‘Bugs’

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 »