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

the code below works sometimes, even with the same input it tends to output this after the second run:
Use of uninitialized value in string eq at /usr/lib/perl5/site_perl/5. +8.6/WWW/LEO.pm line 218, <INFO> line 370. Use of uninitialized value in string eq at /usr/lib/perl5/site_perl/5. +8.6/WWW/LEO.pm line 221, <INFO> line 370. Use of uninitialized value in string eq at /usr/lib/perl5/site_perl/5. +8.6/WWW/LEO.pm line 218, <INFO> line 370. Use of uninitialized value in string eq at /usr/lib/perl5/site_perl/5. +8.6/WWW/LEO.pm line 221, <INFO> line 370. Use of uninitialized value in string eq at /usr/lib/perl5/site_perl/5. +8.6/WWW/LEO.pm line 218, <INFO> line 370. Use of uninitialized value in string eq at /usr/lib/perl5/site_perl/5. +8.6/WWW/LEO.pm line 221, <INFO> line 370.
i wasn't able to figure out on which word it crashes, seems to differ
#!/usr/bin/perl use warnings; use strict; use WWW::LEO; use Data::Dumper; open(INFO, "< /home/metalfan/todo/dictionaries/Vokabeln\ -\ absolut +ion\ gap.csv") || die("can't open datafile: $!"); my @file=<INFO>; for my $entry (@file) { my $n=0; if ($entry =~ m/"(.+)",\s/x) { my $vokabel=$1; my $leo = WWW::LEO->new; $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; } } }
theres another WWW-LEO version on cpan in the bugreports section

Replies are listed 'Best First'.
Re: WWW-LEO, why is my code "crashing"
by Corion (Patriarch) on Dec 29, 2005 at 19:00 UTC

    Your code is not "crashing", Perl just warns you about some events that you might not want. But if you look at your error message, you see two line numbers. One line is for WWW/LEO.pm - in line 218, a value is used that has not been initialized. The second line is for the INFO filehandle. It currently points to line number 370, likely because you have 370 vocables in your info file. If you change your code around a bit, Perl will tell you which word triggers these warnings:

    Instead of

    my @file = <INFO>; foreach my $entry (@file) { ... };
    use
    foreach my $entry (<INFO>) { ... };
    Then, the second line number will tell you the number of the word triggering the problematic behaviour. Of course, you could also output each word before looking it up via WWW::LEO:

    foreach my $entry (@file) { chomp $entry; warn "Looking up '$entry'"; ... };
      somehow the line numbers didn't changed with the new code?

        You don't show any new code, so I can't comment on why the numbers don't change. Most likely, you didn't implement any of my suggestions.

      its not crashing, okay...but something wired is happening, these are the first words from my vob list.
      sometimes the script can handle the input and sometimes not...
      "Abating", "Abdominal"," Unterleibs- [Präfix], Bauch, Hinterleibs, abdominal [ad +j.]" "Ability","Geistige oder körperliche Fähigkeit, Geschicklichkeit, nach + besten Kräften" "Ablative", "Abrupt", "Acquittance","Erfüllung, Verpflichtung, Begleichung" "Addiction", "Admit","1. to admit [v.] einlassen [v.], zugeben [v.], zugestehen +[v.], zulassen [v.] 2. to admit of [v.] zulassen [v.] 3. to admit t +o [v.] aufnehmen in [v.], eingestehen [v.], hereinlassen [v.], zuge +ben [v.]" "Adult","1. adult [n.] Erwachsene [m.,f.] 2. adult [adj.] erwach +sen [adj.]" "Advanced","erweitert [adj.], fortgeschritten [adj.], fortschrittlich +[adj.], vorgerückt [adj.], zukunftsweisend [adj.]" "Affairs", "Affection","Liebe, (Zu)Neigung, Gemütsbewegung -zustand, Stimmung, Er +krankung, leiden" "Afraid", "Allies", "Ancestor","Vorfahr, Ahnherr, Stammvater" "Angles", "Anticipation"," Erwartung [f.], Vorausnahme [f.], Vorwegnahme [f.]" "Anxious"," unruhig [adj.]" "Argued","1. to argue [v.] argumentieren [v.], auseinander setzen [a +usdr.], behaupten [v.], bereden [v.], bestreiten [v.], erörtern [v.] +,streiten (§ p.,pp.: stritt, gestritten) [v.], vorbringen [v.]" "Arise","Entstehen, entspringen, hervorgehen" "Arowse","Pret. Von arise" "Artefact", "Attenuated", "Augmentation", "Awfully"," furchtbar [adv.], schrecklich [adv.]" "Awkward"," eckig [adj.], heikel [adj.], linkisch [adj.], peinlich [a +dj.], tolpatschig [adj.], täppisch [adj.], umständlich [adj.], unang +enehm [adj.], unbeholfen [adj.], ungelenk [adj.], ungeschickt [adj.], + ungünstig [adj.], tapsig* [adj.]" "Baggage",
Re: WWW-LEO, why is my code "crashing"
by ptum (Priest) on Dec 29, 2005 at 19:19 UTC

    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
      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?