It depends on what you want exactly, but here's something that might work for you:
case (/LotID/i) { @lotid = split( /-/, $array[1] ); $lotid = "$lotid[0]"; # fetch the part matching Lot#XXX where XXX is one or + more digits, or die if that doesn't work ($lotid) = $lotid =~ /(Lot#\d+)/ or die "lotid isn't c +orrectly formatted"; $wafer_flow = "$lotid[1]-$lotid[2]"; }
The ($lotid) = ... line makes use of several tricks:

1. assigning the result of a regex match to a list will assing the () delimited parts of that regex to the the members of the list. In this case, there's only one member in the list ($lotid) and one () delimited submatch, so $lotid will get the value of whatever is matched by Lot#\d+

2. the result of assignment to a list is the number of elements assigned to. in this case, 1 if the regex matches or 0 if the regex doesn't match. The ... or die ... part tests for that value and throws an exception if the match failed, since in that case my logic is wrong.

For a reasonably genteel introduction to regexes see perlretut. For (most of) the whole story, see perlre.

As an aside, please consider dropping Switch altogether, it's a fun module but one day it will cause hard to debug problems.


In reply to Re^5: Case Statement by Joost
in thread Case Statement by phimtau123

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.