Hello rkabhi,

As haukex says, the Switch module is deprecated and therefore best avoided. But the problem here is not with the module, but rather with the way it is being used.

First, by giving the switch statement an empty argument, you are matching against the empty string:

use strict; use warnings; use Switch; for ('abc', 'def', 'ghi') { switch () { case /bc/ { print "$_: matches 'bc'\n"; } case /de/ { print "$_: matches 'de'\n"; } case '' { print "EMPTY STRING\n"; } else { print "$_: no match found\n"; } } }

Output:

1:51 >perl 1675_SoPW.pl EMPTY STRING EMPTY STRING EMPTY STRING 1:51 >

You need to specify the string to be matched against: in this case, switch ($_) {.

Second, the next statements in your case clauses do not force another iteration of the enclosing while loop, as you expect. That’s because the Switch module uses next to implement fall-through, as explained in the “Allowing fall-through” section of the Switch documentation. You could avoid this by specifying an explicit target for the next statements; for example (untested):

MAIN_LOOP: while (<READ_NETLIST>) { chomp; s/^\s+//; # Remove leading blanks (if any) in the line # ignore line if it contains comments or initializing words for sp +ectre switch ($_) { case /^[*\/]/i { next MAIN_LOOP; } case /simulator\s+lang/i { next MAIN_LOOP; } case /^include/i { next MAIN_LOOP; } } ... }

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,


In reply to Re: Perl Code Changes Behavior if Two Subroutine definitions are swapped by Athanasius
in thread Perl Code Changes Behavior if Two Subroutine definitions are swapped by rkabhi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.