Using Dumper not triggering a failure

混江龙づ霸主 提交于 2019-12-01 00:22:37

One of the valid syntaxes for print is

print FILEHANDLE LIST

In your program Perl is treating Dumper as a filehandle glob.

Running this code with warnings enabled will tell you:

print() on unopened filehandle Dumper at ...

If you had begun with the standard boilerplate, then you would know:

#!/usr/bin/env perl
#
# name_of_program - what the program does as brief one-liner
#
# Your Name <your_email@your_host.TLA>
# Date program written/released
#################################################################

use 5.10.0;

use utf8;
use strict;
use autodie;
use warnings FATAL => "all";

#  ⚠ change to agree with your input: ↓
use open ":std" => IN    => ":encoding(ISO-8859-1)",
                   OUT   => ":utf8";
#  ⚠ change for your output: ↑ — *maybe*, but leaving as UTF-8 is sometimes better

END {close STDOUT}

our $VERSION = 1.0;

$| = 1;

The answer is that your program is syntactically but not semantically correct. You are printing "something" to the unopened Dumper filehandle-object, because Dumper is in the dative slot for the print method call. That makes Dumper print’s invocant. But you never opened a handle by that name, so you are printing to an uninitialized filehandle.

Use my boilerplate. PLEASE!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!