Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Do yourself a favor and upgrade (Bug in 5.8.0)

by PetaMem (Priest)
on Apr 26, 2005 at 17:22 UTC ( [id://451681]=perlmeditation: print w/replies, xml ) Need Help??

This node is here to demonstrate how upgrading your Perl can automagically make your life easier. The following code does not work as expected in 5.8.0, but does so in 5.8.6
sub sequential { my $self = shift; my $sl_ctl = $self->{slctl}; my $sl_len = scalar(@$sl_ctl); my $mode = $self->{params}->{mode}; my $m_clust = $mt_param{$mode}->{cluster}; my @tl_rtl = (); &log("mt: entering sequential, mode >$mode<...\n"); $m_clust = &get_maxval([1, $m_clust]); for(my $i = 0; $i < $sl_len; $i++) { my $idx_la = &get_minval([$sl_len-1, $i + $m_clust]); my $phrase; my $rawtr; retry: &log("I: $i IDX_LA: $idx_la\n"); $phrase = join ' ', @$sl_ctl[$i..$idx_la]; $rawtr = $self->get_rawtr($phrase); if(@$rawtr) { my $disam = $self->disambiguate($phrase, $rawtr, $i,$idx_la); push @tl_rtl, $disam; } else { if($idx_la > $i) { $idx_la--; goto retry; } push @tl_rtl, $phrase; } $i = $idx_la; } @tl_rtl = &trim(@tl_rtl); $self->{tlrtl} = \@tl_rtl; return TRUE; }
In correct operation, the log looks like this, You see, $idx_la is always defined
Tue Feb  8 20:22:00 2005: mt: entering sequential, mode >level0<...
Tue Feb  8 20:22:00 2005: I: 0 IDX_LA: 1
Tue Feb  8 20:22:00 2005: mt: get_rawtr for >i am< lexl: >xx<.
Tue Feb  8 20:22:00 2005: mt: gives result ><.
Tue Feb  8 20:22:00 2005: I: 0 IDX_LA: 0
Tue Feb  8 20:22:00 2005: mt: get_rawtr for >i< lexl: >xx<.
Tue Feb  8 20:22:00 2005: mt: gives result >ich<.
Tue Feb  8 20:22:00 2005: mt: disambig mode: >0<
Tue Feb  8 20:22:00 2005: I: 1 IDX_LA: 2
Tue Feb  8 20:22:00 2005: mt: get_rawtr for >am going< lexl: >xx<.
Tue Feb  8 20:22:00 2005: mt: gives result ><.
Tue Feb  8 20:22:00 2005: I: 1 IDX_LA: 1
Tue Feb  8 20:22:00 2005: mt: get_rawtr for >am< lexl: >xx<.
Tue Feb  8 20:22:00 2005: mt: gives result >bin<.
Tue Feb  8 20:22:00 2005: mt: disambig mode: >0<
Tue Feb  8 20:22:00 2005: I: 2 IDX_LA: 3
Tue Feb  8 20:22:00 2005: mt: get_rawtr for >going to< lexl: >xx<.
Tue Feb  8 20:22:00 2005: mt: gives result ><.
Tue Feb  8 20:22:00 2005: I: 2 IDX_LA: 2
Tue Feb  8 20:22:00 2005: mt: get_rawtr for >going< lexl: >xx<.
Tue Feb  8 20:22:00 2005: mt: gives result >gehend<.
Tue Feb  8 20:22:00 2005: mt: disambig mode: >0<
Tue Feb  8 20:22:00 2005: I: 3 IDX_LA: 4
Tue Feb  8 20:22:00 2005: mt: get_rawtr for >to sweden< lexl: >xx<.
Tue Feb  8 20:22:00 2005: mt: gives result ><.
Tue Feb  8 20:22:00 2005: I: 3 IDX_LA: 3
Tue Feb  8 20:22:00 2005: mt: get_rawtr for >to< lexl: >xx<.
Tue Feb  8 20:22:00 2005: mt: gives result >zu nach<.
Tue Feb  8 20:22:00 2005: mt: disambig mode: >0<
Tue Feb  8 20:22:00 2005: I: 4 IDX_LA: 5
Tue Feb  8 20:22:00 2005: mt: get_rawtr for >sweden today< lexl: >xx<.
Tue Feb  8 20:22:00 2005: mt: gives result ><.
Tue Feb  8 20:22:00 2005: I: 4 IDX_LA: 4
Tue Feb  8 20:22:00 2005: mt: get_rawtr for >sweden< lexl: >xx<.
Tue Feb  8 20:22:00 2005: mt: gives result ><.
Tue Feb  8 20:22:00 2005: I: 5 IDX_LA: 5
Tue Feb  8 20:22:00 2005: mt: get_rawtr for >today< lexl: >xx<.
Tue Feb  8 20:22:00 2005: mt: gives result >heute<.
Tue Feb  8 20:22:00 2005: mt: disambig mode: >0<
Tue Feb  8 20:22:00 2005: mt: restore_punc.
Tue Feb  8 20:22:00 2005: mt: synthesize.
Tue Feb  8 20:22:00 2005: mt: synthesize: tformat.
Tue Feb  8 20:22:00 2005: mt: writefile & mtinfo.
Tue Feb  8 20:22:00 2005: Time for command 'mt en:de level0 mt_en.txt': 0
On Perl 5.8.0 it does this
Tue Feb  8 20:45:09 2005: mt: entering sequential, mode >level0<...
Tue Feb  8 20:45:09 2005: I: 0 IDX_LA: 1
Tue Feb  8 20:45:09 2005: mt: get_rawtr for >i am< lexl: >xx<.
Tue Feb  8 20:45:09 2005: mt: gives result ><.
Tue Feb  8 20:45:09 2005: I: 0 IDX_LA: 0
Tue Feb  8 20:45:09 2005: mt: get_rawtr for >i< lexl: >xx<.
Tue Feb  8 20:45:09 2005: mt: gives result >ich<.
Tue Feb  8 20:45:09 2005: mt: disambig mode: >0<
Tue Feb  8 20:45:09 2005: I: 1 IDX_LA: 2
Tue Feb  8 20:45:09 2005: mt: get_rawtr for >am going< lexl: >xx<.
Tue Feb  8 20:45:09 2005: mt: gives result ><.
Tue Feb  8 20:45:09 2005: I: 1 IDX_LA:
Tue Feb  8 20:45:09 2005: mt: get_rawtr for >< lexl: >xx<.
Tue Feb  8 20:45:09 2005: mt: gives result ><.
Tue Feb  8 20:45:09 2005: I: 1 IDX_LA: 2
Tue Feb  8 20:45:09 2005: mt: get_rawtr for >am going< lexl: >xx<.
Tue Feb  8 20:45:09 2005: mt: gives result ><.
Tue Feb  8 20:45:09 2005: I: 1 IDX_LA:
Tue Feb  8 20:45:09 2005: mt: get_rawtr for >< lexl: >xx<.
Tue Feb  8 20:45:09 2005: mt: gives result ><.
Tue Feb  8 20:45:09 2005: I: 1 IDX_LA: 2
Tue Feb  8 20:45:09 2005: mt: get_rawtr for >am going< lexl: >xx<.
Tue Feb  8 20:45:09 2005: mt: gives result ><.
Tue Feb  8 20:45:09 2005: I: 1 IDX_LA:
Tue Feb  8 20:45:09 2005: mt: get_rawtr for >< lexl: >xx<.
Tue Feb  8 20:45:09 2005: mt: gives result ><.
Tue Feb  8 20:45:09 2005: I: 1 IDX_LA: 2
ad infinitum...

Bye
 PetaMem
    All Perl:   MT, NLP, NLU

Replies are listed 'Best First'.
Re: Do yourself a favor and upgrade (Bug in 5.8.0)
by brian_d_foy (Abbot) on Apr 27, 2005 at 02:13 UTC

    The better advice to is wait for the .1 releases and let the early adopters get bit with the bugs. :)

    --
    brian d foy <brian@stonehenge.com>
      I like telling people that it wouldn't be called stable if it wasn't stable so they should use the .0 releases, thereby helping guarantee that there are some early adopters to help smoke out the bugs. ;-)
      No, the best advice is to listen to The Man, The Legend, Edsger Dijkstra when he says:
      For a number of years I have been familiar with the observation that the quality of programmers is a decreasing function of the density of go to statements in the programs they produce. More recently I discovered why the use of the go to statement has such disastrous effects, and I became convinced that the go to statement should be abolished from all "higher level" programming languages (i.e. everything except, perhaps, plain machine code). At that time I did not attach too much importance to this discovery; I now submit my considerations for publication because in very recent discussions in which the subject turned up, I have been urged to do so.
      Full paper here: http://www.acm.org/classics/oct95/

      By the way - that paper was written in 1968. You're damn near 40 years behind best practices when you write code with gotos in it.

      20050227 Edit by ysth: p, blockquote tags; linkify url; correct name typo

        By the way - that paper was written in 1968. You're damn near 40 years behind best practices when you write code with gotos in it.

        Please see this thread, and especially this comment:

        "People who just balk at any sight of a goto have at best heard about Dijkstra's article Go To Considered Harmful (which wasn't titles bij Dijkstra, but by Hoare), but never read the paper, or not understood it. Dijkstra just warns that goto can easily lead to unstructured programs, he doesn't say it's evil all the time."

        Bye
         PetaMem
            All Perl:   MT, NLP, NLU

        Oops, so I massively typo'd The Man's name. What can I say, great mind, horrible name for english-speakers to try to remember to spell this early in the morning.
Re: Do yourself a favor and upgrade (Bug in 5.8.0)
by eric256 (Parson) on Apr 26, 2005 at 22:50 UTC

    I don't suppose you could boil that down to an example that could be run on other peoples machines? My eyes gloss over just trying to read that code. ;)


    ___________
    Eric Hodges

      I think this is the problem he's talking about:

      zen% cat t0 #!/usr/bin/perl -w for (my $i = 0; $i < 2; $i++) { my $j = $i + 1; retry: warn "i: $i j: $j\n"; if ($i < $j) { $j--; goto retry; } } zen% /opt/perl-5.8.0/bin/perl t0 i: 0 j: 1 i: 0 j: 0 i: 1 j: 2 Use of uninitialized value in concatenation (.) or string at t0 line 4 +. i: 1 j: Use of uninitialized value in numeric lt (<) at t0 line 6. Segmentation fault (core dumped) zen% /opt/perl-5.8.1/bin/perl t0 i: 0 j: 1 i: 0 j: 0 i: 1 j: 2 i: 1 j: 1 zen%

      Which I'd guess means there was a bug such that using goto to jump up to an enclosing scope after the introduction of some lexicals in that scope introduced an instability that would initially manifest as the lexical becoming undefined, and could eventually lead to a core dump.

      Hugo

Re: Do yourself a favor and upgrade (Bug in 5.8.0)
by demerphq (Chancellor) on Apr 27, 2005 at 17:39 UTC

    You can use [perlfunc://redo] here instead of goto. Simply change the block in the stuff following retry and then change the goto to a redo:

    retry:{ #.... redo retry if $needs_retry; }
    ---
    demerphq

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://451681]
Approved by friedo
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2024-04-16 17:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found