2019年1月29日火曜日

開発環境

初めてのPerl 第7版 (Randal L. Schwartz(著)brian d foy(著)Tom Phoenix(著)近藤 嘉雪(翻訳)嶋田 健志(翻訳)オライリージャパン)の2章(スカラーデータ)、2.12(練習問題)1の解答を求めてみる。

コード

#!/usr/bin/env perl
use utf8;
use v5.18;

$半径 = 12.5;= 3.141592654;
$円周 = 2 * $半径 *;

say $円周;

入出力結果(cmd(コマンドプロンプト)、Terminal)

$ perl sample1.pl
Wide character in print at sample1.pl line 9.
Global symbol "$半径" requires explicit package name (did you forget to declare "my $半径"?) at sample1.pl line 5.
Global symbol "$π" requires explicit package name (did you forget to declare "my $π"?) at sample1.pl line 6.
Global symbol "$円周" requires explicit package name (did you forget to declare "my $円周"?) at sample1.pl line 7.
Global symbol "$半径" requires explicit package name (did you forget to declare "my $半径"?) at sample1.pl line 7.
Global symbol "$π" requires explicit package name (did you forget to declare "my $π"?) at sample1.pl line 7.
Global symbol "$円周" requires explicit package name (did you forget to declare "my $円周"?) at sample1.pl line 9.
Execution of sample1.pl aborted due to compilation errors.
$ perl sample1.pl
78.53981635
$

strict pragma(use strict;)が無い場合は、変数宣言に「my」は必要無かった気がするけどエラーに。

気になったからちょっと確認。

コード

#!/usr/bin/env perl
use utf8;
use v5.10;

$半径 = 12.5;= 3.141592654;
$円周 = 2 * $半径 *;

say $円周;

入出力結果(cmd(コマンドプロンプト)、Terminal)

$ perl sample1.pl
78.53981635
$

コード

#!/usr/bin/env perl
use utf8;
use v5.10;

$半径 = 12.5;= 3.141592654;
$円周 = 2 * $半径 *;

say $円周;

入出力結果(cmd(コマンドプロンプト)、Terminal)

$ perl sample1.pl
78.53981635
$

コード

#!/usr/bin/env perl
use utf8;
use v5.11;

$半径 = 12.5;= 3.141592654;
$円周 = 2 * $半径 *;

say $円周;

入出力結果(cmd(コマンドプロンプト)、Terminal)

$ perl sample1.pl
Wide character in print at sample1.pl line 9.
Global symbol "$半径" requires explicit package name (did you forget to declare "my $半径"?) at sample1.pl line 5.
Global symbol "$π" requires explicit package name (did you forget to declare "my $π"?) at sample1.pl line 6.
Global symbol "$円周" requires explicit package name (did you forget to declare "my $円周"?) at sample1.pl line 7.
Global symbol "$半径" requires explicit package name (did you forget to declare "my $半径"?) at sample1.pl line 7.
Global symbol "$π" requires explicit package name (did you forget to declare "my $π"?) at sample1.pl line 7.
Global symbol "$円周" requires explicit package name (did you forget to declare "my $円周"?) at sample1.pl line 9.
Execution of sample1.pl aborted due to compilation errors.
$

Perlのバージョン5.10までは必要なくて、バージョン5.11から変数宣言に「my」が必須になったみたい。

コード

#!/usr/bin/env perl
use strict;
use utf8;
use v5.10;

$半径 = 12.5;= 3.141592654;
$円周 = 2 * $半径 *;

say $円周;

入出力結果(cmd(コマンドプロンプト)、Terminal)

$ perl sample1.pl
Wide character in print at sample1.pl line 10.
Global symbol "$半径" requires explicit package name (did you forget to declare "my $半径"?) at sample1.pl line 6.
Global symbol "$π" requires explicit package name (did you forget to declare "my $π"?) at sample1.pl line 7.
Global symbol "$円周" requires explicit package name (did you forget to declare "my $円周"?) at sample1.pl line 8.
Global symbol "$半径" requires explicit package name (did you forget to declare "my $半径"?) at sample1.pl line 8.
Global symbol "$π" requires explicit package name (did you forget to declare "my $π"?) at sample1.pl line 8.
Global symbol "$円周" requires explicit package name (did you forget to declare "my $円周"?) at sample1.pl line 10.
Execution of sample1.pl aborted due to compilation errors.
$

strictプラグマを指定した場合は、バージョン5.10の場合にもエラーに。

0 コメント:

コメントを投稿