Reputation: 8208
$ perl -e 'use strict subs; print sysopen(my $temp, "./myfile.txt", O_RDONLY);'
Bareword "O_RDONLY" not allowed while "strict subs" in use at -e line 1
If you run that on the command line, you get that error. I understand why it's an error, and the solution is to use Fnctl
but that's something that has to be installed on the box. People have enough complaints about Perl and I'm trying to give them a tool that (covertly) demonstrates Perl's usefulness and how little hassle it (could) be. This doesn't help.
I'm trying to write a Perl utility that people can use just as a single file, without having to install external libraries. Why is an external module required for a built-in? I understand that O_RDONLY
might be different on different operating systems but so might STDIN
, STDERR
, and STDOUT
but those are usable with use strict subs
.
Upvotes: 1
Views: 227
Reputation: 132913
You can check the status of modules with corelist
, which comes with perl
:
$ corelist Fcntl
Data for 2020-06-20
Fcntl was first released with perl 5
$ corelist Module::CoreList
Data for 2020-06-20
Module::CoreList was first released with perl v5.8.9
Module::Build
is an example of a module that was in core, deprecated, and then removed:
$ corelist Module::Build
Data for 2022-03-13
Module::Build was first released with perl v5.9.4, deprecated (will be CPAN-only) in v5.19.0 and removed from v5.21.0
The STDOUT
, STDERR
, and STDIN
handles are Perl special variables and they know what they are supposed to be when your perl is compiled. Perl doesn't complain about any of the variables it gives you for free (perlvar).
Upvotes: 1
Reputation: 123551
Why is an external module required for a built-in?
Fcntl is not an external module. It is a standard module shipped with Perl. If it fails to load then Perl is not properly installed. But if you want you can use the numeric values check its value and use this instead: perl -MFcntl -E 'say O_RDONLY'
Upvotes: 6