Opps, may have posted in the wrong board by accident, is there I way I can move it? - Update: Sorted, my thanks to the gods.

I've been seeing weird behaviour where regex matches and the $1 .. $X variables seem to get clobbered when using Switch.pm.

EXAMPLE:

sub onSay { my ($playerData, $message) = @_; my @userDetails = getPlayerProperties($playerData); &printDebug('[ON SAY]','INPUT: ' . $message); switch($message) { case m/xxkick #?(\d+) (.+)/i { my $toKick = $1; my $reason = $2; &printDebug('[ON SAY]',"$toKick, $1 || $2, $reason"); } case m/xxban #?(\d+)\s+(\d+)\s+(.+)/i { my $toKick = $1; my $banLength = $2; my $banReason = $3; &printDebug('[ON SAY]',"$1, $2, $3"); } } } #-------------- # Output: #-------------- # 05/10/2010 @ 00:15:05 [ON SAY]: INPUT: xxkick 1206 test # 05/10/2010 @ 00:15:05 [ON SAY]: SGR<1206><STEAM_0:1:2161308><Spectat +or>, SGR<1206><STEAM_0:1:2161308><Spectator> || say, say

Surely the above SHOULD read:

05/10/2010 @ 00:15:05 [ON SAY]: INPUT: xxkick 1206 test 05/10/2010 @ 00:15:05 [ON SAY]: 1206, 1206 || test, test

Am I doing anything obviously wrong? I can replicate this every time and have come across it before, using if, elsif etc. works as it should. i.e.

if ($message =~ m/xxkick #?(\d+) (.+)/i) { my $toKick = $1; my $reason = $2; &printDebug('[ON SAY]',"$toKick, $1 || $2, $reason"); }

Works as it should. Any ideas?


In reply to Switch.pm Regular Expression matches getting clobbered? by AxleUK

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.