in reply to How to determine if 'ref' is wanted? (ala 'wantarray')

Even if it's easy to check if the next op in the caller is a dereference, a function that returns any of 1) a reference to the array, 2) the contents of the array, or 3) the number of elements in the array is way too magical.

Instead of

@{ $o->Ts } my $ref = \@{ $o->Ts }; my @array = $o->Ts; my $count = $o->Ts;

You'll get fewer headaches with

@{ $o->Ts } my $ref = $o->Ts; my @array = @{ $o->Ts }; my $count = @{ $o->Ts };

p.s. Hey, what's with P.M. not recognizing ">" in code and xlating it to ">"? Doesn't HTML convert text entities everywhere?

Cause it saves you a lot of work.

Replies are listed 'Best First'.
Re^2: How to determine if 'ref' is wanted? (ala 'wantarray')
by perl-diddler (Chaplain) on Nov 07, 2011 at 19:58 UTC

    So you are giving me reasons why you think it shouldn't generally be done. That's fine. I agree.

    But ... I'm still looking for an answer to the question.

    Besides, 'way to magical'...having a function that acts like an array... yeah...right...*NOT*....

    People have functions that grab onto operators and such all the time...those are no less 'magical'. It's call 'syntactic sugar'.... might NOT be something I'd use everywhere, since in an OO setup, you don't usually want to give the 'client' direct access to your array, but in some cases, the efficiency is worth the trade off -- especially if you are your own client and know you'll be "well behaved"...:-)...

    As for :

    p.s. Hey, what's with P.M. not recognizing ">" in code and xlating it to ">"? Doesn't HTML convert text entities everywhere?

    Cause it saves you a lot of work.

    It also violates the HTML standard.  I.e. it breaks tools that use the standard.  If PM used a keyword that wasn't part of the HTML standard, like 'literal', then there wouldn't be a prob, but redefining standard HTML...UG...  better would be a PM specific tag, like pm_code... then its likely to never conflict with any future reserved words...

     

    Try https://addons.mozilla.org/en-US/firefox/addon/write-area/.

    It brings features to pm, that pm 'should' have builtin, (most sites that have html composition have builtin html editors....but not slashdot, and not perlmonks...)...  perlmonks is more like a social site -- a community site, than a new site -- so IMO, I think it should move toward the 'friendly side' rather than expecting people to write code to post a message...But that' just my feeling...

    At least slashdot is smart enough to recognize plaintext and leave it as such .. whereas here...all formatting is stripped,  and a proprietary formatting language is used...ug!

    About the above addon...to use it...when you get a write box, just right-click and say 'edit in a write area'  brings up a little thml editor right in the window.  (I sorta prefer it when it comes up outside the window as it does on most sites...not sure why it is different here...(same on sysinternals site)...edits inline)...

     

     

     

      I'm still looking for an answer to the question.

      Weird, because I answered it. You need to look at the opcode tree to see if the next op in the caller is a dereference.

      People have functions that grab onto operators and such all the time.

      No idea what that means.

      It's call 'syntactic sugar'

      I didn't say being magical was bad, I said what you wanted was too magical. There is syntactic sugar, and then there is syntactic sludge.


      It also violates the HTML standard.

      So? I'm sure you'll find it's violated in many other ways since this site doesn't accept HTML, but something similar to it.

      Just put a <p> at the front of every paragraph, and put computer text (input, output, code) in <c>...</c> tags.

      If PM used a keyword that wasn't part of the HTML standard, like 'literal', then there wouldn't be a prob,

      Actually, it wouldn't help at all. Those tools you mention would misparse the contents of the tag no matter what it's called.

      At least slashdot is smart enough to recognize plaintext and leave it as such .. whereas here...all formatting is stripped, and a proprietary formatting language is used...ug!

      Your "ug" is misplaced. It should be attached to "all formatting is stripped". Throwing out the baby with the bathwater is not a good solution.