Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Net::Dict not acting expectedly

by DarknessX (Scribe)
on Mar 16, 2003 at 19:34 UTC ( #243513=perlquestion: print w/replies, xml ) Need Help??

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'

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://243513]
Approved by pfaut
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2021-12-02 00:31 GMT
Find Nodes?
    Voting Booth?
    R or B?

    Results (15 votes). Check out past polls.