use strict; use warnings; warn "running"; 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 RGBColor $blurple = RGBColor->new(red => 75, blue => 200, green => +0); print "blurple's blue is $blurple->{blue}\n"; $blurple->new(red => 175, blue => 100, green => 100); print $blurple->{orange}; ### BANGS AT COMPILETIME print "blurple's blue is $blurple->{blue}\n";
No such class field "orange" in variable $blurple of type RGBColor at +d:/tmp/pm/t_fields_pm.pl line 35. Compilation exited abnormally with code 255 at Sun Feb 14 23:04:10
runs fine after uncommenting the orange line
running at d:/tmp/pm/t_fields_pm.pl line 5. blurple's blue is 200 blurple's blue is 100
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
In reply to Re^4: do separate hashes share common keys?
by LanX
in thread do separate hashes share common keys?
by LanX
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |