in reply to Is there a wantobject like wantarray?
#!/usr/bin/perl use warnings; use strict; use feature qw{ say }; { package MyObj; use overload '""' => \&both, fallback => 1; sub new { my ($class, $first, $last) = @_; bless { first => $first, last => $last }, $class } sub first { $_[0]->{first} } sub both { "@{ $_[0] }{qw{first last}}" } } sub makeupname { 'MyObj'->new(qw(John Smith)); } say makeupname(); say makeupname()->first;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Is there a wantobject like wantarray?
by LanX (Saint) on Sep 25, 2014 at 15:49 UTC | |
by tobyink (Canon) on Sep 26, 2014 at 00:31 UTC | |
by LanX (Saint) on Sep 26, 2014 at 08:14 UTC | |
by tobyink (Canon) on Sep 26, 2014 at 09:00 UTC | |
by LanX (Saint) on Sep 26, 2014 at 09:08 UTC |