in reply to calling regular expressions returned by functions?

The problem is that  m// binds by default to  $_ in the absence of an explicit binding, e.g.,  $s =~ m{pattern}; A poor, naked  qr// doesn't know what to bind to and must always be bound explicitly as BrowserUk has done.

In general, the interpolation of a constant into a regex is messy:
    use constant FOO => qr{ foo }xms;
    print 'got foo' if 'foo' =~ m{ @{[ FOO ]} }xms;

The use of a Readonly constant makes things neater:
    use Readonly;
    Readonly my $FOO => qr{ foo }xms;
    print 'got foo' if 'foo' =~ m{ $FOO }xms;
but BrowserUk will tell you that the Readonly module has some dirty little secrets of its own. YMMV.

Replies are listed 'Best First'.
Re^2: calling regular expressions returned by functions?
by Anonymous Monk on Mar 29, 2012 at 19:27 UTC

    Ah! This is where I blundered; I didn't understand regex binding.

    Thank you all for your patience & taking the time to share your insight. This will help me write more robust code.