|Perl Monk, Perl Meditation|
Identifying if a variable is the product of a qr//by demerphq (Chancellor)
|on Apr 25, 2002 at 09:49 UTC||Need Help??|
demerphq has asked for the
wisdom of the Perl Monks concerning the following question:
Yesterday broquaint and I were chatting and he mentioned a code snippet like this
To which I replied (stupidly) that that wouldnt work, the product of qr// is just a blessed scalar that happens to stringify itself as the regular expression it contains, and that reblessing would destroy the magic. So that it would have to be like this
Well I was wrong! as the code below shows.
So, the blessed version seems to match correctly, but when stringified returns the stringification of a scalar ref. And Dumper doesnt handle it correctly.
As far as I cant tell from the above results precompiled regexes are in fact base types from the POV of the perl programmer, like real scalars, arrays or hashes or globs. (Actually im sure that the subject of perls types could fill an entire meditiation or five :-) And as far as I can tell there is _no_way_ to determine whether a scalar reference is actually a reference to a real scalar or to a regex.
Can anybody tell me if im wrong, and if so how do I differentiate
Yves / DeMerphq