Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Oh, I'd definitely make that an object. If only so I could either make normalized_designation a computed attributed, or at least write a set_normalized_designation that looked something like:
sub set_normalized_designation { my $self = shift; my $designation = shift; $self->ensure_normalization($designation); $self->{normalized_designation} = shift; } sub ensure_normalization { my $self = shift; my $designation = shift; $designation =~ /.../ or die "$designation is not correctly normalized"; }
You could certainly argue that this might be considered long winded, but writing things this way makes assumptions explicit and ensure that they're enforced.

Of course, in Perl 6 you can have your cake and eat it:

class Thing { my $.title is rw; my $.standard_directory is rw; # Where graphics etc are found my $.designation is rw; my Hash $.def; # Use another class? method normalized_designation { my $normalized_des = $.designation; $normalized_des =~ s/.../.../; return $normalized_des; } }
Now, I might be a little behind on Perl 6 OO, but ISTR that setting is rw on object attributes will autogenerate accessors. If not I'm sure someone will subclass Object to do the right thing.

Note that, in not much more space than it took to comment your hash you have an object, and, for free you get a restricted set of keys, and your dependent field removed and replaced with a computation, and you've got somewhere to hang common behaviour relating to this data structure.

Damn, but I want Perl 6 soon.


In reply to Re: Re: Re: Re: Perl Programming guidlines/rules by pdcawley
in thread Perl Programming guidelines/rules by hakkr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2024-04-16 09:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found