Debian Codegraph @

upstream/debian-unstable/man3/CORE.3perl

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45)
3 .\"
4 .\" Standard preamble:
5 .\" ========================================================================
6 .de Sp \" Vertical space (when we can't use .PP)
7 .if t .sp .5v
8 .if n .sp
9 ..
10 .de Vb \" Begin verbatim text
11 .ft CW
12 .nf
13 .ne \\$1
14 ..
15 .de Ve \" End verbatim text
16 .ft R
17 .fi
18 ..
19 .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20 .ie n \{\
21 . ds C` ""
22 . ds C' ""
23 'br\}
24 .el\{\
25 . ds C`
26 . ds C'
27 'br\}
28 .\"
29 .\" Escape single quotes in literal strings from groff's Unicode transform.
30 .ie \n(.g .ds Aq \(aq
31 .el .ds Aq '
32 .\"
33 .\" If the F register is >0, we'll generate index entries on stderr for
34 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35 .\" entries marked with X<> in POD. Of course, you'll have to process the
36 .\" output yourself in some meaningful fashion.
37 .\"
38 .\" Avoid warning from groff about undefined register 'F'.
39 .de IX
40 ..
41 .nr rF 0
42 .if \n(.g .if rF .nr rF 1
43 .if (\n(rF:(\n(.g==0)) \{\
44 . if \nF \{\
45 . de IX
46 . tm Index:\\$1\t\\n%\t"\\$2"
47 ..
48 . if !\nF==2 \{\
49 . nr % 0
50 . nr F 2
51 . \}
52 . \}
53 .\}
54 .rr rF
55 .\" ========================================================================
56 .\"
57 .IX Title "CORE 3perl"
58 .TH CORE 3perl 2025-11-16 "perl v5.40.1" "Perl Programmers Reference Guide"
59 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
60 .\" way too many mistakes in technical documents.
61 .if n .ad l
62 .nh
63 .SH NAME
64 CORE \- Namespace for Perl's core routines
65 .SH SYNOPSIS
66 .IX Header "SYNOPSIS"
67 .Vb 3
68 \& BEGIN {
69 \& *CORE::GLOBAL::hex = sub { 1; };
70 \& }
71 \&
72 \& print hex("0x50"),"\en"; # prints 1
73 \& print CORE::hex("0x50"),"\en"; # prints 80
74 \& CORE::say "yes"; # prints yes
75 \&
76 \& BEGIN { *shove = \e&CORE::push; }
77 \& shove @array, 1,2,3; # pushes on to @array
78 .Ve
79 .SH DESCRIPTION
80 .IX Header "DESCRIPTION"
81 The \f(CW\*(C`CORE\*(C'\fR namespace gives access to the original built-in functions of
82 Perl. The \f(CW\*(C`CORE\*(C'\fR package is built into
83 Perl, and therefore you do not need to use or
84 require a hypothetical "CORE" module prior to accessing routines in this
85 namespace.
86 .PP
87 A list of the built-in functions in Perl can be found in perlfunc.
88 .PP
89 For all Perl keywords, a \f(CW\*(C`CORE::\*(C'\fR prefix will force the built-in function
90 to be used, even if it has been overridden or would normally require the
91 feature pragma. Despite appearances, this has nothing to do with the
92 CORE package, but is part of Perl's syntax.
93 .PP
94 For many Perl functions, the CORE package contains real subroutines. This
95 feature is new in Perl 5.16. You can take references to these and make
96 aliases. However, some can only be called as barewords; i.e., you cannot
97 use ampersand syntax (\f(CW&foo\fR) or call them through references. See the
98 \&\f(CW\*(C`shove\*(C'\fR example above. These subroutines exist for all keywords except the following:
99 .PP
100 \&\f(CW\*(C`_\|_DATA_\|_\*(C'\fR, \f(CW\*(C`_\|_END_\|_\*(C'\fR, \f(CW\*(C`and\*(C'\fR, \f(CW\*(C`cmp\*(C'\fR, \f(CW\*(C`default\*(C'\fR, \f(CW\*(C`do\*(C'\fR, \f(CW\*(C`dump\*(C'\fR,
101 \&\f(CW\*(C`else\*(C'\fR, \f(CW\*(C`elsif\*(C'\fR, \f(CW\*(C`eq\*(C'\fR, \f(CW\*(C`eval\*(C'\fR, \f(CW\*(C`for\*(C'\fR, \f(CW\*(C`foreach\*(C'\fR, \f(CW\*(C`format\*(C'\fR, \f(CW\*(C`ge\*(C'\fR,
102 \&\f(CW\*(C`given\*(C'\fR, \f(CW\*(C`goto\*(C'\fR, \f(CW\*(C`grep\*(C'\fR, \f(CW\*(C`gt\*(C'\fR, \f(CW\*(C`if\*(C'\fR, \f(CW\*(C`last\*(C'\fR, \f(CW\*(C`le\*(C'\fR, \f(CW\*(C`local\*(C'\fR, \f(CW\*(C`lt\*(C'\fR,
103 \&\f(CW\*(C`m\*(C'\fR, \f(CW\*(C`map\*(C'\fR, \f(CW\*(C`my\*(C'\fR, \f(CW\*(C`ne\*(C'\fR, \f(CW\*(C`next\*(C'\fR, \f(CW\*(C`no\*(C'\fR, \f(CW\*(C`or\*(C'\fR, \f(CW\*(C`our\*(C'\fR, \f(CW\*(C`package\*(C'\fR,
104 \&\f(CW\*(C`print\*(C'\fR, \f(CW\*(C`printf\*(C'\fR, \f(CW\*(C`q\*(C'\fR, \f(CW\*(C`qq\*(C'\fR, \f(CW\*(C`qr\*(C'\fR, \f(CW\*(C`qw\*(C'\fR, \f(CW\*(C`qx\*(C'\fR, \f(CW\*(C`redo\*(C'\fR, \f(CW\*(C`require\*(C'\fR,
105 \&\f(CW\*(C`return\*(C'\fR, \f(CW\*(C`s\*(C'\fR, \f(CW\*(C`say\*(C'\fR, \f(CW\*(C`sort\*(C'\fR, \f(CW\*(C`state\*(C'\fR, \f(CW\*(C`sub\*(C'\fR, \f(CW\*(C`tr\*(C'\fR, \f(CW\*(C`unless\*(C'\fR,
106 \&\f(CW\*(C`until\*(C'\fR, \f(CW\*(C`use\*(C'\fR, \f(CW\*(C`when\*(C'\fR, \f(CW\*(C`while\*(C'\fR, \f(CW\*(C`x\*(C'\fR, \f(CW\*(C`xor\*(C'\fR, \f(CW\*(C`y\*(C'\fR
107 .PP
108 Calling with
109 ampersand syntax and through references does not work for the following
110 functions, as they have special syntax that cannot always be translated
111 into a simple list (e.g., \f(CW\*(C`eof\*(C'\fR vs \f(CWeof()\fR):
112 .PP
113 \&\f(CW\*(C`chdir\*(C'\fR, \f(CW\*(C`chomp\*(C'\fR, \f(CW\*(C`chop\*(C'\fR, \f(CW\*(C`defined\*(C'\fR, \f(CW\*(C`delete\*(C'\fR, \f(CW\*(C`eof\*(C'\fR, \f(CW\*(C`exec\*(C'\fR,
114 \&\f(CW\*(C`exists\*(C'\fR, \f(CW\*(C`lstat\*(C'\fR, \f(CW\*(C`split\*(C'\fR, \f(CW\*(C`stat\*(C'\fR, \f(CW\*(C`system\*(C'\fR, \f(CW\*(C`truncate\*(C'\fR, \f(CW\*(C`unlink\*(C'\fR
115 .SH "OVERRIDING CORE FUNCTIONS"
116 .IX Header "OVERRIDING CORE FUNCTIONS"
117 To override a Perl built-in routine with your own version, you need to
118 import it at compile-time. This can be conveniently achieved with the
119 \&\f(CW\*(C`subs\*(C'\fR pragma. This will affect only the package in which you've imported
120 the said subroutine:
121 .PP
122 .Vb 3
123 \& use subs \*(Aqchdir\*(Aq;
124 \& sub chdir { ... }
125 \& chdir $somewhere;
126 .Ve
127 .PP
128 To override a built-in globally (that is, in all namespaces), you need to
129 import your function into the \f(CW\*(C`CORE::GLOBAL\*(C'\fR pseudo-namespace at compile
130 time:
131 .PP
132 .Vb 5
133 \& BEGIN {
134 \& *CORE::GLOBAL::hex = sub {
135 \& # ... your code here
136 \& };
137 \& }
138 .Ve
139 .PP
140 The new routine will be called whenever a built-in function is called
141 without a qualifying package:
142 .PP
143 .Vb 1
144 \& print hex("0x50"),"\en"; # prints 1
145 .Ve
146 .PP
147 In both cases, if you want access to the original, unaltered routine, use
148 the \f(CW\*(C`CORE::\*(C'\fR prefix:
149 .PP
150 .Vb 1
151 \& print CORE::hex("0x50"),"\en"; # prints 80
152 .Ve
153 .SH AUTHOR
154 .IX Header "AUTHOR"
155 This documentation provided by Tels <nospam\[email protected]> 2007.
156 .SH "SEE ALSO"
157 .IX Header "SEE ALSO"
158 perlsub, perlfunc.