1CORE(3pm) Perl Programmers Reference Guide CORE(3pm)
2
3
4
6 CORE - Pseudo-namespace for Perl's core routines
7
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
17 The "CORE" namespace gives access to the original built-in functions of
18 Perl. There is no "CORE" package, and therefore you do not need to use
19 or require an hypothetical "CORE" module prior to accessing routines in
20 this namespace.
21
22 A list of the built-in functions in Perl can be found in perlfunc.
23
25 To override a Perl built-in routine with your own version, you need to
26 import it at compile-time. This can be conveniently achieved with the
27 "subs" pragma. This will affect only the package in which you've
28 imported the said subroutine:
29
30 use subs 'chdir';
31 sub chdir { ... }
32 chdir $somewhere;
33
34 To override a built-in globally (that is, in all namespaces), you need
35 to import your function into the "CORE::GLOBAL" pseudo-namespace at
36 compile time:
37
38 BEGIN {
39 *CORE::GLOBAL::hex = sub {
40 # ... your code here
41 };
42 }
43
44 The new routine will be called whenever a built-in function is called
45 without a qualifying package:
46
47 print hex("0x50"),"\n"; # prints 1
48
49 In both cases, if you want access to the original, unaltered routine,
50 use the "CORE::" prefix:
51
52 print CORE::hex("0x50"),"\n"; # prints 80
53
55 This documentation provided by Tels <nospam-abuse@bloodgate.com> 2007.
56
58 perlsub, perlfunc.
59
60
61
62perl v5.12.4 2011-06-01 CORE(3pm)