Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: Perl 5.10 given/when tricks and caveats

by sasdrtx (Friar)
on Sep 05, 2008 at 00:40 UTC ( #709154=note: print w/ replies, xml ) Need Help??

in reply to Perl 5.10 given/when tricks and caveats

I think your first example would be more useful if you just printed the value of $i on every iteration. I don't have perl 5.10 handy myself.

This does seem like odd behavior. No switch/select I'm familiar with (I admit that's not many) tries to match multiple cases/whens. Obviously in C the limitations of case tests to simple constants would make that behavior silly.

A switch group is generally used as a prettier form of a series of if/elsif/.../else statements. The Perl implementation of continue seems to just change the next elsif to a plain if. And in that case, why not just use a plain if?

I'd like to see an example of how this behavior was expected to be used.

Comment on Re: Perl 5.10 given/when tricks and caveats
Replies are listed 'Best First'.
Re^2: Perl 5.10 given/when tricks and caveats
by hardburn (Abbot) on Sep 05, 2008 at 05:21 UTC

    The real trick is that C's switch statement can be compiled down to a jump table in the assembly, which is the main reason it's so constrained. We had a discussion on this a long while back.

    "There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.

Re^2: Perl 5.10 given/when tricks and caveats
by mr_mischief (Monsignor) on Sep 05, 2008 at 04:23 UTC
    You may be right about the presentation of that example. I arrived at the code showing the differences through a bit of a convoluted process. I was playing with the differences in a few directions for myself to decide just what to show. I think the code I posted before shows as much about that process as about the resulting idea for the post. Hopefully your idea presents it more clearly to those of you whose voices are outside my head. ;-)

    Here's the new C and Perl code and their output:

    Perl code:

    C code:

    And here's the new output for the Perl:

    1: 1 2: 1 3: 1 4: 1 5: 0
    And the C:
    1: 4 2: 3 3: 2 4: 1 5: 0

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2016-05-06 12:12 GMT
Find Nodes?
    Voting Booth?