Hello SergioQ,

Your question is not very clear to me. What do you mean with: "messy blessed text messes"? I searched for something in your recent posts, quickly, I cant find something relevant.

You got good replies (see LanX's one). As he said bless is used to add something like a flag to a reference. The flag says: I'm not from here. I come from Whatever::Package so see there to see how I behave. When some method of this blessed reference is called (a method is simple sub) the first parameter received will be the object itself, generally named $self but just as convention.

A full minimalist example

use strict; use warnings; # usually this is defined inside a perl module # at ./Whatever/Package.pm package Whatever::Package; # this is the constructor. generally called new but is not a rule sub new{ # we will receive the class name as first argument my $class = shift; # and just need to return a reference (an anonymous hash {} in thi +s case) blessed into $class return bless {}, $class; } sub first { my $self = shift; print "We are inside package ",__PACKAGE__, " we received \$self because it is blessed into ",ref $sel +f,"\n"; } # usually this is defined inside a perl module # at ./Another/Example/Package.pm package Another::Example::Package; # note the same NAME for the sub sub first { my $self = shift; print "This method will no be called unless the object is blessed +into Another::Example::Package"; } # usually the script will use Whatever::Package (defined inside a perl + module ./Whatever/Package.pm) # but we can merely switch back to the default package 'main' package main; # again a sub with the same name sub first{ print "We are inside package ",__PACKAGE__," I'm not a method but +a bare lone sub\n"; } # test the local sub first(); # let 'instanciate' an object of the Whatever::Package class my $obj = Whatever::Package->new(); print "\$obj is now a blessed reference. It is blessed into ",ref $obj +,"\n"; # above we have 3 subs named first. Which one will be called? $obj->first();

Start with the standard documentation. See package too.

If you can get a copy of the old but valid Perl CookBook read:

  • Chapter 11: References and Records
  • Chapter 12: Packages, Libraries, and Modules
  • Chapter 13: Classes, Objects, and Ties

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

    In reply to Re: Where can I learn more about blessed data? -- a basic example by Discipulus
    in thread Where can I learn more about blessed data? by SergioQ

    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.