in reply to Uninitialized variable matches regex

The * operator matches zero or more of the linked character type - undef has exactly 0 occurences of digits, and thus matches. Try + to avoid this one. It's all in the Quantifiers section of perlre.

Update: A little more detail. Your regex has the following three components:

  1. ^ - Match the beginning of the line
  2. \d* - Match a digit character 0 or more times
  3. $ - Match the end of the line (or before newline at the end)

The act of binding a scalar to the regular expression stringifies it (as Anonymous Monk points out below). That is why your number assignment matches. So once you bind undef (with appropriate warning suppression), undef becomes '', which has a start, 0 digits and an ending, and thus matches.

As an interesting note, you also match on $id = "\n";, and if you use the m modifier, you match $id = "My favorite number is:\n42\nWhat's yours?";

Replies are listed 'Best First'.
Re^2: Uninitialized variable matches regex
by Rodster001 (Pilgrim) on Mar 23, 2009 at 20:56 UTC
    Oh, crap... I knew that. Or, at least I did at one time, but it got overwritten. Thanks, man.