Skip to content

Instantly share code, notes, and snippets.

@oshiro-kazuma
Created August 27, 2012 18:01
Show Gist options
  • Save oshiro-kazuma/3490892 to your computer and use it in GitHub Desktop.
Save oshiro-kazuma/3490892 to your computer and use it in GitHub Desktop.
Perlのオブジェクトの動きを確認
#!/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