Thanks for all your comments. It's been interesting reading! I'm a Unix system administrator by trade and even though I've been using Perl since the early 90s most of the time I'm just using it for quick and dirty hacks to get something working now. I relish the chance to do more advanced things with it, hence my question today.

I guess the main reason I wanted to use chained methods is because I've seen them used elsewhere and when it came to writing this current application I figured I'd try to figure them out for myself. Not because I particularly need them but just because I was curious. :-)

One of the things I love about Perl is that once you know the basics you can figure out how to do a lot of complicated things just by "guessing." So, in this instance I thought "I wonder if all I need to do is return $self to get chaining to work?" It did work but broke something else which is what prompted my question here.

I'll never forget when I found out about hashes of hashes. It turned out that I'd been using things like $foo{'bar'}{'baz'} for years because it just seemed logical to me to do it but I never realised that what I was doing actually had a name and that what I was really doing was storing an anonymous hash with a key of 'baz' in another hash with a key of 'bar'. Once I figured that out it opened up a whole world of complex data structures but it all stemmed from me just assuming that I could put multiple keys on a hash to create a multi-dimensional array and Perl would DWIM.

Anyway, that's just my longwinded way of saying thanks! I've been lurking here for a while reading people's questions and answers but this was my first question and even though it had a simple answer it has made me think a lot more about what I'm doing!


In reply to Re: Method Chaining and Accessors by linenoise
in thread Method Chaining and Accessors by linenoise

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.