in reply to WWW-LEO, why is my code "crashing"

So, it is always possible that something in your data is causing trouble. You might try to figure out what is on line 370 of your INFO file, and show it to us. One thing about your code that makes me nervous is that you are rather trusting and don't seem to use ref() to check if $resultpair or $leo->en_de are array references before you cast them to arrays. Personally, I like to make sure of things like that.

Also, you check $leo->num_results, where you ought to be checking the return from $leo->query(). Looking at the source code for WWW-LEO I see that num_results is set in _parse_response, yet that method is only called if the query is successful. For an unsuccessful query, you'll get the num_results value from the last query, which probably isn't what you want.

I haven't used this module, so please take my comments with several tablespoons of salt. :)

Update: Sigh, I should look at the code more carefully. Note that inside the query method, there is a call to reset, which sets num_results to zero. Please scratch that last remark.


No good deed goes unpunished. -- (attributed to) Oscar Wilde

Replies are listed 'Best First'.
Re^2: WWW-LEO, why is my code "crashing"
by metalfan (Novice) on Dec 29, 2005 at 20:10 UTC
    as you can see from the data ive posted the english words use only a-z. most from the code is from WWW-LEO docs.
    using just the word ive posted the error changes to:
    Use of uninitialized value in string eq at /usr/lib/perl5/site_perl/5. +8.6/WWW/LEO.pm line 221, <INFO> line 32. Use of uninitialized value in string eq at /usr/lib/perl5/site_perl/5. +8.6/WWW/LEO.pm line 218, <INFO> line 32. Use of uninitialized value in string eq at /usr/lib/perl5/site_perl/5. +8.6/WWW/LEO.pm line 221, <INFO> line 32. Use of uninitialized value in string eq at /usr/lib/perl5/site_perl/5. +8.6/WWW/LEO.pm line 218, <INFO> line 32. Use of uninitialized value in string eq at /usr/lib/perl5/site_perl/5. +8.6/WWW/LEO.pm line 221, <INFO> line 32.

    line 32 is the last line from the file...same with the 370.
      heres the complete code with the file for my input:
      #!/usr/bin/perl use warnings; use strict; use diagnostics; use WWW::LEO; use Data::Dumper; open(INFO, "< /home/metalfan/todo/dictionaries/Vokabeln\ -\ absolut +ion\ gap.csv.test") || die("can't open datafile: $!"); #my @file=<INFO>; #for my $entry (@file) foreach my $entry (<INFO>) #for my $entry ($file[10]..$file[15]) { my $n=0; if ($entry =~ m/"(.+)",\s/x) { if ($entry =~ m/Baggage/) { exit; } my $vokabel=$1; #print "$1\n"; my $leo = WWW::LEO->new; #$leo->query("@ARGV"); $leo->query("$vokabel"); if ($leo->num_results) { my $i; foreach my $resultpair (@{$leo->en_de}) { printf "%3d: %-40s %s\n", ++$i, @$resultpair; } } else { print "Sorry, your query for ’%s’gave no results.\n", $leo +->query; } } }
      the input file:
      http://rapidshare.de/files/10146384/Vokabeln_-_absolution_gap.csv.test.html

      it's still "crashing". mostly every third run didnt succeed...
      what could that be?
        CLOSED switched to html format for my input