Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^4: do separate hashes share common keys?

by LanX (Saint)
on Feb 14, 2021 at 22:06 UTC ( [id://11128382]=note: print w/replies, xml ) Need Help??


in reply to Re^3: do separate hashes share common keys?
in thread do separate hashes share common keys?

you missed to declare "blurple" as of type RGBColor

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";

OUTPUT

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 (Monsignor) on Feb 15, 2021 at 19:57 UTC
    my RGBColor $self = shift;

    Is this "typing" standard? First time I have seen this (excuse my ignorance).

      > Is this "typing" standard?

      Well, it's documented, see my:

      my TYPE VARLIST : ATTRS

      But this is (unfortunately) the only use case (I'm aware of)

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11128382]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2024-03-28 08:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found