in reply to Re^3: do separate hashes share common keys?
in thread do separate hashes share common keys?
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: do separate hashes share common keys?
by bliako (Abbot) on Feb 15, 2021 at 19:57 UTC | |
by LanX (Saint) on Feb 15, 2021 at 20:11 UTC |