warningsã¢ã¸ã¥ã¼ã«
Perl
›
ã¢ã¸ã¥ã¼ã«
›
here
ãè¦åã表示ããã«ã¯warningsãã©ã°ãã使ç¨ãã¾ãã
use warnings;
ãPerlã«ããã¦ã¯ãããã©ã«ãã®ç¶æ ã§ã¯ãè¦åã¯è¡¨ç¤ºããããã¹ã¯ãªãããå®è¡ããã¾ããwarningsãã©ã°ãã使ãã°ãè¦åã表示ããããã¨ãã§ãã¾ããã¹ã¯ãªãããæ¸ãå ´åã¯ãstrictãã©ã°ãã¨ãããã¦ãå¿ ãè¨è¿°ããããã«ãã¾ãããã
ããè¦ãè¦å
ãããè¦ãã§ãããè¦åã«ã¤ãã¦ããã¤ã解説ãã¦ããã¾ãã
æªå®ç¾©å¤ã®ä½¿ç¨
ãæªå®ç¾©å¤ã使ç¨ããã¨è¦åã表示ããã¾ãã以ä¸ã®ã¹ã¯ãªããã§ã¯ãæªå®ç¾©ã®å¤ããã®ã¾ã¾printé¢æ°ã§åºåãã¦ãã¾ã£ã¦ãã¾ãã
use warnings; # æªå®ç¾©å¤ãä½¿ç¨ my $str; print $str;
ã次ã®ãããªè¦åã表示ããã¾ãã
Use of uninitialized value $str in print at a.pl line 6
ãè±èªãªã®ã§ç¿»è¨³ãã¾ãã
printã«ããã¦æªå®ç¾©å¤$strã使ç¨ãã¦ãã¾ãã6è¡ç®ã
ãæªå®ç¾©ãå©ç¨ãã¦ããã¨ããå 容ã®è¦åãçºçããå ´åã¯ãå¤æ°ã«å¤ãä»£å ¥ããªãã¾ã¾ã«ãªã£ã¦ããã¨ãããã¨ã§ããã¤ã¾ããã¹ã¯ãªããã«ãã¹ãããã¨ãããã¨ã§ããã¹ã¯ãªãããä¿®æ£ãã¦ããã®è¦åã表示ãããªãããã«ãã¾ãããã
æååãã¨ã³ã³ã¼ãããã¦ããªã
ãæ¥æ¬èªãªã©ã®ãã«ããã¤ãæåã使ç¨ããã¨ãã«ãæååãã¨ã³ã³ã¼ãããã¦ããªããã¨ãç¥ãããè¦åã表示ãããå ´åãããã¾ãã以ä¸ã¯è¦åãçºçããã¹ã¯ãªããã§ãã
use warnings; use utf8; # æååãã¨ã³ã³ã¼ãããã¦ããªã my $str = 'ããã«ã¡ã¯'; print $str;
ã次ã®ãããªè¦åã表示ããã¾ãã
Wide character in print at a.pl line 7.
ãè±èªãªã®ã§ç¿»è¨³ãã¾ãã
ã¯ã¤ãæåã使ç¨ããã¦ãã¾ãã7è¡ç®ã
ãããã¯ãæååãã¨ã³ã³ã¼ããããã«åºåããã¦ããã¨ãããã¨ãæå³ãã¦ãã¾ããã§ãããããã¡ãã¨ã¨ã³ã³ã¼ããã¾ãããã
use warnings; use utf8; use Encode 'encode'; # æååãã¨ã³ã³ã¼ãããã¦ããªã my $str = 'ããã«ã¡ã¯'; print encode('UTF-8', $str);
ãµãã«ã¼ãã³ãåå®ç¾©ããã¦ãã
ããµãã«ã¼ãã³ããäºå以ä¸å®ç¾©ããã¨ãã¯ããµãã«ã¼ãã³ãåå®ç¾©ããã¦ããã¨ããè¦åãçºçãã¾ãã以ä¸ã¯è¦åãçºçããã¹ã¯ãªããã§ãã
use warnings; # ãµãã«ã¼ãã³ã®åå®ç¾© sub one { 1 } sub one { 1 }
ã次ã®ãããªè¦åã表示ããã¾ãã
Subroutine one redefined at a.pl line 5.
ãè±èªãªã®ã§ç¿»è¨³ãã¾ãã
ãµãã«ã¼ãã³oneãåå®ç¾©ããã¦ãã¾ãã5è¡ç®ã
ããµãã«ã¼ãã³ãåå®ç¾©ãã¦ããã¨ãã¯ãé常ã¯ééãã®å¯è½æ§ãé«ãã®ã§ãããä¸æçã«ãµãã«ã¼ãã³ãç½®ãæãããã¨ããå ´åãã¨ãã©ãçºçãã¾ãããã®ãããªå ´åã¯ããã®è¦åãææ¢ãããã¨ãã§ãã¾ãã
no warnings 'redefine';
ããã®å®ç¾©ãè¡ãã¨ããµãã«ã¼ãã³ã®åå®ç¾©ã®è¦åã¯çºçããªããªãã¾ãã
use warnings; no warnings 'redefine'; # ãµãã«ã¼ãã³ã®åå®ç¾©ã®è¦åã¯çºçããªã sub one { 1 } sub one { 1 }
ããµãã«ã¼ãã³ã®åå®ç¾©ã®è¦å以å¤ã®è¦åãä¼¼ããããªæ¹æ³ã§ææ¢ãããã¨ãã§ãã¾ãããã©ãååã¨ãã¦è¦åã¯ææ¢ãã¦ã¯ããã¾ãããè¦åãçºçãã¦ããåå ã®é¨åã®ã»ããä¿®æ£ãã¹ãã§ãã
ãµãã«ã¼ãã³ã®åå®ç¾©ã®è¦åãæå¶ãã
ãéçºä¸ã«ãã°ããã£ã¦ãæ¥é½ä¿®æ£ããªãã¨ãããªãã¨ãã¯ãã¢ã³ãã¼ããããå½ã¦ããã¨ãã¨ãã©ãããã¾ãããã¢ã³ãã¼ãããã¨ããã®ã¯ããµãã«ã¼ãã³ãã¡ã½ããã®å®ç¾©ãä¸æ¸ããã¦ãæ£ããåãã«ãã¦ããããã¨ã§ãã
ãã§ããµãã«ã¼ãã³ã®åå®ç¾©ãè¡ãã¨ãè¦åãçºçãã¾ãããã®è¦åã表示ããªãããã«ããã«ã¯warningsãã©ã°ãã§ãµãã«ã¼ãã³ã®åå®ç¾©ã®è¦åãã¨ããããã«ã³ã³ãã¤ã©ã«æ示ãã¦ããã¾ãã
no warnings 'redefine';
ãããã§è¦åã表示ãããªããªãã¾ããããã¯ã¬ãã·ã«ã«ãªã¹ã³ã¼ããæã¡ã¾ãã以ä¸ã¯ã¢ã¸ã¥ã¼ã«ã®ã¡ã½ãããä¸æ¸ããããµã³ãã«ã§ãã