Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

(tye)Re: uninitialized weirdness

by tye (Sage)
on Nov 17, 2000 at 00:08 UTC ( [id://42043]=note: print w/replies, xml ) Need Help??


in reply to uninitialized weirdness

It turns out that $mode is what is undefined. Perl is reporting the wrong line number because it has optimized the entire if/elsif/else into a "case" (or "switch") statement.

Update: Well, the case/switch statement bit may or may not enter into it. I recall old documentation talking about simple if/elsif/else being internally optimized into a case/switch type of flow control. What I have been able to verify is that Perl is not recording line number of the elsif lines. One easy way to see this is:

perl -d script.pl DB<2> l 32-46 32: if($line =~ m/<!-- LHS movie -->/) { 33: $mode ="LHS"; 34: $moviecounter++; 35: $internal=0; 36 } elsif ($line =~ m/<!-- RHS movie -->/) { 37: $mode = "RHS"; 38: $moviecounter++; 39: $internal=0; 40 } elsif ($line =~ m/<!-- theater -->/) { 41: $mode = "theater"; 42: $counter++; 43: $moviecounter=-1; 44: $internal=0; 45 } elsif ($mode eq "LHS") { 46: if ($internal == 6 ) {
and notice that the elsif lines don't have colons (":") after their line numbers. This is probably worth bringing to the attention of p5p to see if it can be fixed.

        - tye (but my friends call me "Tye")

Replies are listed 'Best First'.
Re: uninitialized weirdness
by Dominus (Parson) on Nov 17, 2000 at 08:31 UTC
    Says tye:
    > I recall old documentation talking about simple
    > if/elsif/else being internally optimized into a
    > case/switch type of flow control.
    Perl 4 did that, but the feature was lost in Perl 5.

    Every once in a while someone suggests adding it back to Perl 5, and what happens next is that everyone jumps in and suggests one stupid bonus feature after another. "Oh, it should do XYZ also." "Yes, and PDQ as well." After that, it sounds too complicated so nobody wants to do it.

    Damian Conway has an implementation of a switch statement based on source filters, but I think all it does is compile your code into an if-elsif internally; you don't get the optimization that you would get in C.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-05-21 01:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found