Blessing is the usual technique for creating all objects. All it does is mark the 'thingy' (scalar, hash or whatever) pointed to by the reference as belonging to a particular package. Doing this allows the method call syntax to work, ie
$ref->method(@args)
is shorthand to tell perl to execute
Foo::Bar::method($ref, @args)
where Foo::Bar is the package that the thingy pointed to by $ref has been blessed into. If the 'method' sub doesn't exist in Foo::Bar, then Perl looks in the packages listed in @Foo::Bar::ISA for a sub called 'method', and so on.

Tying is something completely unrelated, and only has a marginal conection with OO (in the sense that it's implemented using OO). It's used when you want to take control of how a variable is accessed.

tie @arr, Foo::Bar, @args
calls
Foo::Bar->TIEARRAY(@args)
and this sub is supposed to return a blessed object of some type (not necessarily an array). Perl then attaches this object to the variable in question (@arr), and marks it as being tied. Any subsequent access of this variable (eg $arr[3] = 4) is intercepted, and rather than modifying the contents of the real array, a method is called on its associated object, eg
$hidden_object->STORE(3,4);

Dave.


In reply to Re: Difference between tie and bless by dave_the_m
in thread Difference between tie and bless by GoCool

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.