in reply to What means: "bless { @_ } => $class;"?
Or does { @_ } create an annoymous hash from the elements of the argument array and if so, how does that => $class fit in?The braces here create a reference to an anonymous hash. The curly braces are probably the most overloaded symbols in Perl. Sometimes the usage is even ambiguous and perl doesn't do what you would expect.
=> is essentially the same as a comma except that sometimes you don't need to quote what's on the left side of it (which isn't relevant here).
You could also write this as:
orsub new { my $class = shift; my %self = @_; bless \%self, $class; }
sub new { my $class = shift; my $self = { @_ }; bless $self, $class; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: What means: "bless { @_ } => $class;"?
by BerntB (Deacon) on Apr 24, 2006 at 02:13 UTC | |
by merlyn (Sage) on Apr 24, 2006 at 13:12 UTC |