Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Mark Jason Dominus gave a talk about the life and death of pseudohashes. (I’d heard of them but had no idea what they actually were before seeing this video.)

I infer from it that fields.pm originated as a convenient interface for pseudohashes and that after they went away fields.pm was kept around mainly for backwards compatibility and reworked to use restricted hashes.

I’d never played with fields.pm before, but I spent a few minutes with it just now and I can guess why it’s not very popular: it doesn't make much of an object. It doesn’t auto-generate accessors or a constructor. (Code is pasted below.) The attempted method call $blurple->blue blows up because there's no blue method. Also, the copy of %params into %{$self} will blow up if you pass any parameter name other than "red", "green", or "blue".

#!/usr/bin/perl package RGBColor { use fields qw(red green blue); sub new { my RGBColor $self = shift; my %params = @_; unless (ref $self) { $self = fields::new($self); } %{$self} = %params; return $self; } } my $blurple = RGBColor->new(red => 75, blue => 200, green => 0); print "blurple's blue is $blurple->{blue}\n"; print "blurple's blue is " . $blurple->blue ."\n"; # kaboom, no such +method
– Aaron
Preliminary operational tests were inconclusive. (The damn thing blew up.)

In reply to Re^3: do separate hashes share common keys? by Radiola
in thread do separate hashes share common keys? by LanX

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 learning in the Monastery: (2)
As of 2024-04-25 19:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found