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
use strict; | |
use IO::File; | |
my $fh = new IO::File("somefile.txt", "r") || die "can't open file. $!¥n"; | |
# 引数としてファイルハンドル(実体はIO::Fileオブジェクト)を渡す | |
&some_process($fh); | |
sub some_process { | |
# ファイルハンドルの受け取り |
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
use strict; | |
use IO::File; | |
my $stdin_fh = new IO::File; | |
# STDIN(標準入力)を$stdin_fhに紐付ける | |
$stdin_fh->fdopen(fileno(STDIN), "r"); | |
# 後は$stdin_fhを通常のIO::Fileオブジェクトの様に使える。 |
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
use strict; | |
use Scalar::Util qw/looks_like_number/; | |
my $var1 = 123; | |
my $var2 = 'abc'; | |
if (looks_like_number($var1)) { | |
# $var1は数値なのでif文はtrueになる | |
print "数値です", "¥n"; | |
} |
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
use parent qw/Class::Accessor/; | |
__PACKAGE__->mk_accessors(qw/foo/); | |
# you can use | |
$self->foo; # gettter | |
$self->foo('some value'); # setter |
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
use Scalar::Util qw/blessed/; | |
my $obj = new MyClass; | |
if (blessed($obj)) { | |
print "is MyClass object.", "¥n"; | |
print ref($obj); # you get class name (in this situation, you get MyClass) | |
} else { | |
print "is not any object.", "¥n"; | |
} |
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
my $obj = new MyClass; | |
# MyClassにメソッドfooが存在するかを調べる | |
if ($obj->can('foo')) { | |
print "存在する", "¥n"; | |
} else { | |
print "存在しない", "¥n"; | |
} |
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
$ cpan install Module::Starter | |
$ cpan install Module::Starter::PBP | |
$ cpan install Module::Starter::Smart |
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
$ perl -MModule::Starter::PBP=setup | |
Please enter your full name : [your name] | |
Please enter an email address : [your email address] |
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
plugins: Module::Starter::PBP Module::Starter::Smart |
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
$ module-starter --module=DataStracture::LinkedList |