This syntax is used in combination with the fields and base pragmas to detect access to non-declared attributes at compile time.

It works like this (tested in 5.8.5):

#!/usr/bin/perl -w BEGIN { print "Compile time\n"; } package Foo; use fields qw(some_attribute); sub new { return fields::new(@_); } sub test { my Foo $self = shift; # note the my Foo $self $self->{does_not_exist} = 1; } package main; my Foo $foo = Foo->new(); print "run time\n"; $foo->test(); print "ok\n"; __OUTPUT__ Compile time No such pseudo-hash field "does_not_exist" in variable $self of type F +oo at test.pl line 16.
and if we remove the Foo in my Foo $self at line 15 (in sub test {})
Compile time run time No such pseudo-hash field "does_not_exist" at test.pl line 16.

Programming Perl 3 and the warnings also mention pseudo-hashes, but since perl v5.8.x 5.9 they've been replaced by restricted hashes in the "fields" pragma.

updated: fields.pm still uses pseudohashes in perl 5.8.x


In reply to Re: What does "my Foo $bar" do? by Joost
in thread What does "my Foo $bar" do? by bgreenlee

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.