I came across code like this in trying to work out a bug in Term::ReadLine::Perl5.

#!/usr/bin/perl use strict; use Term::ReadLine; my $term = Term::ReadLine::Stub->new('test'); # $term is a blessed array reference print $term, ' ', $term->OUT, "\n"; # output is: Term::ReadLine::Stub=ARRAY(0x9d73a7c) GLOB(0x9da48a8)

My question is how does $x->OUT seem to get to be the same thing as $x->[1] (if I have this right and I might not).

I find this confusing, do others as well? If so, given that for compatibility there the object is an array references, is there a less confusing way to write this. Or is this way preferable, given that's how it is in the documentation?

I should say that I think although Perl allows you to bless an array reference, I think it is a mistake in Term::Readline::Stub to do so.


In reply to [SOLVED] How does this tricky Perl code in Term::ShellUI using Term::ReadLine dereference an Array? by rockyb

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.