3 CORE - Namespace for Perl's core routines
8 *CORE::GLOBAL::hex = sub { 1; };
11 print hex("0x50"),"\n"; # prints 1
12 print CORE::hex("0x50"),"\n"; # prints 80
13 CORE::say "yes"; # prints yes
15 BEGIN { *shove = \&CORE::push; }
16 shove @array, 1,2,3; # pushes on to @array
20 The C<CORE> namespace gives access to the original built-in functions of
21 Perl. The C<CORE> package is built into
22 Perl, and therefore you do not need to use or
23 require a hypothetical "CORE" module prior to accessing routines in this
26 A list of the built-in functions in Perl can be found in L<perlfunc>.
28 For all Perl keywords, a C<CORE::> prefix will force the built-in function
29 to be used, even if it has been overridden or would normally require the
30 L<feature> pragma. Despite appearances, this has nothing to do with the
31 CORE package, but is part of Perl's syntax.
33 For many Perl functions, the CORE package contains real subroutines. This
34 feature is new in Perl 5.16. You can take references to these and make
35 aliases. However, some can only be called as barewords; i.e., you cannot
36 use ampersand syntax (C<&foo>) or call them through references. See the
37 C<shove> example above. These subroutines exist for all overridable
38 keywords, except for C<dump> and the infix operators. Calling with
39 ampersand syntax and through references does not work for the following
40 functions, as they have special syntax that cannot always be translated
41 into a simple list (e.g., C<eof> vs C<eof()>):
43 C<chdir>, C<chomp>, C<chop>, C<each>, C<eof>, C<exec>, C<keys>, C<lstat>,
44 C<pop>, C<push>, C<shift>, C<splice>, C<stat>, C<system>, C<truncate>,
45 C<unlink>, C<unshift>, C<values>
47 =head1 OVERRIDING CORE FUNCTIONS
49 To override a Perl built-in routine with your own version, you need to
50 import it at compile-time. This can be conveniently achieved with the
51 C<subs> pragma. This will affect only the package in which you've imported
58 To override a built-in globally (that is, in all namespaces), you need to
59 import your function into the C<CORE::GLOBAL> pseudo-namespace at compile
63 *CORE::GLOBAL::hex = sub {
68 The new routine will be called whenever a built-in function is called
69 without a qualifying package:
71 print hex("0x50"),"\n"; # prints 1
73 In both cases, if you want access to the original, unaltered routine, use
76 print CORE::hex("0x50"),"\n"; # prints 80
80 This documentation provided by Tels <nospam-abuse@bloodgate.com> 2007.
84 L<perlsub>, L<perlfunc>.