in reply to Risks in the oblivious use of qr//

The first time I printed a qr// as a scalar, I was enlightened. If I would change anything about the current documentation, I'd add: "try print qr/ABC/i as a scalar to see how all of the options are permanently compiled in."

The odd thing to me is that it bothers to keep the /x option. If you precompile a regex, why not strip all the whitespace and comments and force (?-x)? But that's not a big deal to me. When wearing my app-space hat, I presume the actual compiled regex is hidden and this is just a magic scalar representation.

--
[ e d @ h a l l e y . c c ]

Replies are listed 'Best First'.
Re^2: Risks in the oblivious use of qr//
by Aristotle (Chancellor) on Aug 11, 2003 at 21:49 UTC
    Which is indeed what's going on.
    $ perl -wle'$_=qr/foo/; print ref; print $$_' Regexp Use of uninitialized value in print at -e line 1.
    qr// returns a blessed reference which, well, doesn't point at anything. At least not anything you can see from the Perl end of things.

    Makeshifts last the longest.

Re: Re: Risks in the oblivious use of qr//
by diotalevi (Canon) on Aug 11, 2003 at 22:14 UTC

    The implementation stores the original string internally to the compiled (and opaque) regex and when it constructs a stringified version it just slaps on a "(?..:" and ")" around the original string. Perl doesn't go to the trouble of actually normallizing the regex - it just outputs what it was originally given.