in reply to What does "my Foo $bar" do?
It works like this (tested in 5.8.5):
and if we remove the Foo in my Foo $self at line 15 (in sub test {})#!/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.
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
|
|---|