Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Converting Hashes to Objects

by haukex (Bishop)
on May 17, 2020 at 13:13 UTC ( #11116851=perlmeditation: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    use Util::H2O;
    my $hash = h2o { foo => "bar", x => "y" }, qw/ more keys /;
    print $hash->foo, "\n";  # prints "bar"
    $hash->x("z");  # setter
    
  2. or download this
    my $struct = { hello => { perl => { world => "yay" } } };
    h2o -recurse, $struct;
    print $struct->hello->perl->world, "\n";  # prints "yay"
    
  3. or download this
    my $obj = h2o -meth, {
        one => 123, two => 456,
    ...
            return $self->one + $self->two;
        } };
    print $obj->sum, "\n";  # prints "579"
    
  4. or download this
    h2o -class=>'Point', -new, -meth, {
            angle => sub { my $self = shift; atan2($self->y, $self->x) },
    ...
    my $two = Point->new(x=>3, y=>4);
    $two->y(5);
    printf "%.4f\n", $two->angle;  # prints 1.0304
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://11116851]
Approved by marto
Front-paged by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2020-09-19 00:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If at first I donít succeed, I Ö










    Results (114 votes). Check out past polls.

    Notices?