> What happens when a ref is blessed into a non-existent class. Afterall bless's 2nd argument is a string and not a package qualifier.

You don't reveal the answer on purpose?

The package/class is created.

you can check by inspecting the %main:: stash, where all packages live

DB<30> bless [1,2,3] => 'nonexistent' DB<31> p $main::{'nonexistent::'} *main::nonexistent:: DB<32>

and I think ° it's not only the typeglob but also the stash %nonexistent:: is created, which will result in several hundreds of bytes of overhead

DB<32> p *{$main::{'nonexistent::'}}{HASH} HASH(0x2e7b830) DB<33>

So better don't try to automatically bless into millions of pseudo packages ...

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

PS: According to some statistics this was my 10000st post here ... frightening.

update

°) I couldn't find a pure Perl way to check if the HASH slot of a package:: like entry is filled, without autovivifying that package. It's a very quantum-brainf*ck thing, the observation is changing the result.

Update

For clarification: using bless to solve the semipredicate problem is totally fine in my eyes.

Just be aware that the package will exist. And this globally.

So you should care about a naming convention in your own namespace.


In reply to Re: Blessing with unknown classnames (updated x 2) by LanX
in thread Blessing with unknown classnames by bliako

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.