in reply to Re^2: Why reftype and blessed are making my life harder than it needs to be
in thread Why reftype and blessed are making my life harder than it needs to be

It's easy to bless into "". This trades on knowledge that package names are null terminated strings.

bless( ..., "\0" )

⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

  • Comment on Re^3: Why reftype and blessed are making my life harder than it needs to be
  • Download Code

Replies are listed 'Best First'.
Re^4: Why reftype and blessed are making my life harder than it needs to be
by jdhedden (Deacon) on Feb 10, 2006 at 18:09 UTC
    It's easy to bless into "": bless(..., "\0")
    This seems pathological. All you end up with is a ref that is blessed, but can only execute methods in UNIVERSAL. What practical and legitimate purpose would this serve? And better yet, what functions/modules/applications/etc. does it break in the process? For example, if you use Data::Dumper on such an object, and then eval that string, you won't get the same results (because the eval will create an object in package 'main').

    Just because you can do something, doesn't mean you should.

      It breaks nothing, it's just a string. I think, maybe, the only time you'd ever bless into "" is when you wanted to have an object pretend it wasn't an object in the eyes of something else. Most anything else that uses ref() isn't going to be able to tell that this is an object.

      ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Re^4: Why reftype and blessed are making my life harder than it needs to be
by Perl Mouse (Chaplain) on Feb 11, 2006 at 19:53 UTC
    That sounds like a bug to me. Internally, all Perl strings are zero terminated, but on the language level, Perl is supposed to be better than C, and be able to deal with "\0" correctly. Here it doesn't. It seems that bless [], "\0" and bless [], "\0foo" are blessed into the same package.
    Perl --((8:>*

      Yes, I suppose so, but it's long standing and doesn't impede most people. Packages are the only null terminated string in perl. You might be able to get perl to leak memory if you blessed into things with lots of data after the null.

      ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊