私はPerlオブジェクトを学んでいました。モジュールファイルcreate_schedules.pmに簡単なコンストラクターを書きました。
#!/usr/bin/perl -w
#
package create_schedules;
use strict;
use warnings;
use diagnostics;
sub new {
my $class = shift;
my %params = @_;
my $self=bless{
_para1=>$params{'mypara1'},
_para2=>$params{'mypara2'}
},$class;
return $self;
}
1;
メインファイルmain.plにオブジェクトを作成しています:
#!/usr/bin/perl -w
use strict;
use warnings;
use diagnostics;
use lib::my_module;
sub _start(){
print "Main Function Started\n";
create_schedules::new(
'mypara1' => 'This is mypara1',
'mypara2' => 'This is mypara2',
);
}
_start();
main.pl を実行するとすぐに、次のエラーが発生しました。
Main Function Started
Odd number of elements in hash assignment at lib/create_schedules.pm line 9 (#1)
(W misc) You specified an odd number of elements to initialize a hash,
which is odd, because hashes come in key/value pairs.