1CORE(3pm)              Perl Programmers Reference Guide              CORE(3pm)
2
3
4

NAME

6       CORE - Namespace for Perl's core routines
7

SYNOPSIS

9           BEGIN {
10               *CORE::GLOBAL::hex = sub { 1; };
11           }
12
13           print hex("0x50"),"\n";                     # prints 1
14           print CORE::hex("0x50"),"\n";               # prints 80
15           CORE::say "yes";                            # prints yes
16
17           BEGIN { *shove = \&CORE::push; }
18           shove @array, 1,2,3;                        # pushes on to @array
19

DESCRIPTION

21       The "CORE" namespace gives access to the original built-in functions of
22       Perl.  The "CORE" package is built into Perl, and therefore you do not
23       need to use or require a hypothetical "CORE" module prior to accessing
24       routines in this namespace.
25
26       A list of the built-in functions in Perl can be found in perlfunc.
27
28       For all Perl keywords, a "CORE::" prefix will force the built-in
29       function to be used, even if it has been overridden or would normally
30       require the feature pragma.  Despite appearances, this has nothing to
31       do with the CORE package, but is part of Perl's syntax.
32
33       For many Perl functions, the CORE package contains real subroutines.
34       This feature is new in Perl 5.16.  You can take references to these and
35       make aliases.  However, some can only be called as barewords; i.e., you
36       cannot use ampersand syntax (&foo) or call them through references.
37       See the "shove" example above.  These subroutines exist for all
38       keywords except the following:
39
40       "__DATA__", "__END__", "and", "cmp", "default", "do", "dump", "else",
41       "elsif", "eq", "eval", "for", "foreach", "format", "ge", "given",
42       "goto", "grep", "gt", "if", "last", "le", "local", "lt", "m", "map",
43       "my", "ne", "next", "no", "or", "our", "package", "print", "printf",
44       "q", "qq", "qr", "qw", "qx", "redo", "require", "return", "s", "say",
45       "sort", "state", "sub", "tr", "unless", "until", "use", "when",
46       "while", "x", "xor", "y"
47
48       Calling with ampersand syntax and through references does not work for
49       the following functions, as they have special syntax that cannot always
50       be translated into a simple list (e.g., "eof" vs eof()):
51
52       "chdir", "chomp", "chop", "defined", "delete", "eof", "exec", "exists",
53       "lstat", "split", "stat", "system", "truncate", "unlink"
54

OVERRIDING CORE FUNCTIONS

56       To override a Perl built-in routine with your own version, you need to
57       import it at compile-time.  This can be conveniently achieved with the
58       "subs" pragma.  This will affect only the package in which you've
59       imported the said subroutine:
60
61           use subs 'chdir';
62           sub chdir { ... }
63           chdir $somewhere;
64
65       To override a built-in globally (that is, in all namespaces), you need
66       to import your function into the "CORE::GLOBAL" pseudo-namespace at
67       compile time:
68
69           BEGIN {
70               *CORE::GLOBAL::hex = sub {
71                   # ... your code here
72               };
73           }
74
75       The new routine will be called whenever a built-in function is called
76       without a qualifying package:
77
78           print hex("0x50"),"\n";                     # prints 1
79
80       In both cases, if you want access to the original, unaltered routine,
81       use the "CORE::" prefix:
82
83           print CORE::hex("0x50"),"\n";               # prints 80
84

AUTHOR

86       This documentation provided by Tels <nospam-abuse@bloodgate.com> 2007.
87

SEE ALSO

89       perlsub, perlfunc.
90
91
92
93perl v5.38.2                      2023-11-30                         CORE(3pm)
Impressum