DarknessX has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to use Net::Dict, but having issues. Here's an example.
#!/usr/bin/perl -w use strict; use Net::Dict; my $dict=Net::Dict->new(''); my @words=<STDIN>; foreach (@words){ chomp; print "$dict->define('$_')"; } #but that returns Net::Dict=GLOB(0x8271660)->define('word') #so I'll try this: my $word=$dict->define('banana'); print $word; #this returns ARRAY(0x825d3ec)
Any clues what I'm doing wrong? Thanks in advance.
-----BEGIN GEEK CODE BLOCK----- Version: 3.1 GPA/P/S d+ s++:+ a--- C++ UL++ P++>++++ L++ E W++ N o? K? w-- !O M- V? + PS++ PE- Y PGP- t 5- X+ R* tv-- b++ !DI D---(+) G e- h-- r++ y? ------END GEEK CODE BLOCK-----

Replies are listed 'Best First'.
Re: Net::Dict not acting expectedly
by jasonk (Parson) on Mar 16, 2003 at 19:44 UTC

    The documentation tells you that define() returns an array ref, which contains multiple arrayrefs, each of which lists the dictionary searched and the definition of that word from that dictionary. So what you need is this:

    foreach(@{$dict->define('banana')}) { # check each result print "$_->[0]: $_->[1]\n"; # 0:dictionary 1:definition }

    By the way, Data::Dumper is the perfect tool for debugging these types of things, just use print Dumper($dict->define('banana')); and you can see at a glance what the structure of the data you are getting back is.

    We're not surrounded, we're in a target-rich environment!
Re: Net::Dict not acting expectedly
by Chmrr (Vicar) on Mar 16, 2003 at 19:48 UTC

    You're doing nothing wrong, just not reading the documentation close enough. This is the documented behavior. This is because ->define will return several different results, one or more from each dictionnary that it has. For instance, one of the definitions for "moose" can be gotten via:

    my $d = Net::Dict->new(''); print $d->define("moose")->[0][1];

    perl -pe '"I lo*`+$^X$\"$]!$/"=~m%(.*)%s;$_=$1;y^`+*^e v^#$&V"+@( NO CARRIER'