開発環境
- OS X Lion - Apple(OS)
- TextWrangler(Text Editor) (BBEditの機能制限無料版、light版)
- Script言語:Perl
『続・初めてのPerl 改訂版』(Randal L. Schwartz, brian d foy, Tom Phoenix 著、伊藤 直也、田中 慎司、吉川 英興 監訳、株式会社ロングテール/長尾 高弘 訳、オライリー・ジャパン、2006年、ISBN4-87311-305-9) の5章(リファレンスとスコープ), 5.9(練習問題)1を解いてみる。
1.
ハッシュにハッシュリファレンス(スカラー)を代入しているのがまずいところ。
中括弧を丸括弧に修正すればいい。
やり方の1つ。(「やり方は何通りもある」(TIMTOWTDI(There Is More Than One Way To Do It.)))
コード(TextWrangler)
#!/usr/bin/env perl use strict; use warnings; my %passenger_1 = ( name => 'Ginger', age => 22, occupation => 'Movie Star', real_age => 35, hat => undef, ); my %passenger_2 = ( name => 'Mary Ann', age => 19, hat => 'bonnet', favorite_food => 'corn', ); my @passengers = (\%passenger_1, \%passenger_2);
入出力結果(Terminal)
$ ./sample.pl Reference found where even-sized list expected at ./sample.pl line 5. Reference found where even-sized list expected at ./sample.pl line 13. $ ./sample.pl $ $
0 コメント:
コメントを投稿