in reply to Re^6: fall through switch/case in perl
in thread fall through switch/case in perl

Fair enough, but in TimToady's original, he had 'CASE'.($var+0) which avoids dieing.

P:\test>perl -le" print 1; $var = 'foo'; goto 'CASE'.($var+0); CASE0: +print 2;" 1 2

And that allows CASE0: to become the default.

The only situation this doesn't cover is when $var is undef'd; but then none of the other solutions handle that (except the do{ local $^W; $var + 0 }; I suggested).


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
"Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon

Replies are listed 'Best First'.
Re^8: fall through switch/case in perl
by etcshadow (Priest) on Sep 07, 2004 at 06:34 UTC
    Yes, but what if $var were 11? (Insert Spinal-Tap joke here).

    Also, as I said: when it comes to the behavior of undef (as the value of $var), shouldn't the surrounding scope's notion of whether or not to warn on undef apply here? Why should this be different (in that specific regard: i.e., whether or not to warn on using an undefined value) than, say, $var == 10 (etetera). I would think that if warnings were on, it SHOULD warn, and if warnings were not on, then it should NOT warn... and that's what you get. The presence of an eval doesn't change that fact.

    I'm confused... are we arguing or agreeing? :-D

    ------------ :Wq Not an editor command: Wq
      I'm confused... are we arguing or agreeing? :-D

      Agreeing--with gusto :).

      Yes, but what if $var were 11?

      Ah! I (stupidly) didn't test that one. Point made.

      (Insert Spinal-Tap joke here).

      Actually, if you're so tough that you can make light of a spinal tap, I think I'm gonna agree with you--whatever you say :).


      Examine what is said, not who speaks.
      "Efficiency is intelligent laziness." -David Dunham
      "Think for yourself!" - Abigail
      "Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon
        I wasn't making light of a spinal tap, an unbelievably painful procedure that I don't even want to contemplate; I was referring to the movie "This Is Spinal Tap" about the (fictitious) band by name Spinal Tap. One of the most classic movie scenes of all time must be the one in which the band's lead guitarist is explaining why this particular amp is so good: most amps only go up to ten, but this one goes to eleven.

        Why not make it go to ten, but make ten louder?

        <dumb-struck silence>... But this one goes to eleven.

        Rent the movie, you'll be glad you did.

        ------------ :Wq Not an editor command: Wq