Alright, I should have seen that, or at least tried it. The problem is that create is called before join (obviously) so the way the return of join will be used is unknown at that time. threads allows you to indicate in which context you want your sub to be called (void, scalar or list) (and if you didn't know that, you probably always called your sub in a scalar context), but not to indicate what will be done of the returned value(s).

Unless the sub passed as a parameter to threads->create can be your tail method, you could just check (caller 1)[3] eq '(eval)' before trying to use want.

If this sub can be your tail method, be sure to add {'void' => 1} as the first parameter to threads->create when you're not going to use the return of join(). Then you could have: print " ..and Im a tail!\n" unless defined wantarray and want "OBJECT"

This is probably a bad idea if you want to be able to use the return value of your method, which can be called by thread->create, and can be the tail method. Why are trying to do that by the way? Maybe you've just set foot on a XY Problem and could avoid using want altogether.


In reply to Re^3: Finding the end of a method-chain by Eily
in thread Finding the end of a method-chain by std3rr

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.