Created
August 27, 2012 18:01
-
-
Save oshiro-kazuma/3490892 to your computer and use it in GitHub Desktop.
Perlのオブジェクトの動きを確認
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use Data::Dumper; | |
my $obj = Hoge->new({ | |
str => 'http://hogehoge/', | |
hoge => 'foobar' | |
}); | |
warn Dumper $obj; | |
# ${$_[0]}; とやっていることは同じなはず…! | |
warn Dumper ${$obj}; | |
warn ${$obj}->{str}; | |
# 値を変えれる | |
${$obj}->{str} = "http://www.perl-beginners.org/"; | |
warn ${$obj}->{str}; | |
# blessの引数も変わっている | |
warn Dumper $obj; | |
package Hoge { | |
sub new { | |
my $class = shift; | |
my $opt = shift; | |
bless \$opt, $class; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment