Perlã§ãªãã¸ã§ã¯ãæåã復ç¿ä¸
ã¨ããã§
my $counter = {"value" => 0}; print "$counter\n"; # HASH(0x1008001f0) bless $counter, Counter; print "$counter\n"; # Counter=HASH(0x1008001f0)
ã¦ãªãã¨ãããã¨use strictæã«ã¯ãBareword "Counter" not allowedãã£ã¦è¨ããããbless $counter, "Counter";ãªã大ä¸å¤«ã
説æã®é½åã§æ示çã«ããã±ã¼ã¸ã¨åç §ãblessããããããªã®ã ããæååã§ããã®ã¯ã©ããªãã ãããï¼ããã±ã¼ã¸ããã¡ã¼ã¹ãã¯ã©ã¹ã®ãªãã¸ã§ã¯ãã§ãããããªèª¤è§£ããããªãããã«æ示çã«æååã§blessããã¹ããªã®ããããã¨ãä½è¨ãªãã¨ã«æ°ãåãããªãããã«Barewordã§ãã£ã¡ããã¹ããªã®ãããã¡ããæ®éã¯Counter->newã¨ãã§å¼ã¶ããå®ç¨ä¸ãããåé¡ã«ãªãã±ã¼ã¹ã¯ãªããã ãããã©ã
use strict; use warnings; { package Counter; sub push{ my $values = shift; $values->{count}++; print "$values->{count}å¹\n"; } sub new{ my $class = shift; my $values = {count => shift}; bless $values, $class; } } { my $counter = {"value" => 0}; print "$counter\n"; # HASH(0x1008001f0) bless $counter, "Counter"; print "$counter\n"; # Counter=HASH(0x1008001f0) $counter->push; # 1å¹ $counter->push; # 2å¹ my $c2 = Counter->new; $c2->push; # 1å¹ $counter->push; # 3å¹ }