Debian Codegraph @

upstream/opensuse-tumbleweed/man3/CORE.3pm

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man v6.0.2 (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 .\" Required to disable full justification in groff 1.23.0.
57 .if n .ds AD l
58 .\" ========================================================================
59 .\"
60 .IX Title "CORE 3pm"
61 .TH CORE 3pm 2026-03-09 "perl v5.42.1" "Perl Programmers Reference Guide"
62 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
63 .\" way too many mistakes in technical documents.
64 .if n .ad l
65 .nh
66 .SH NAME
67 CORE \- Namespace for Perl\*(Aqs core routines
68 .SH SYNOPSIS
69 .IX Header "SYNOPSIS"
70 .Vb 3
71 \& BEGIN {
72 \& *CORE::GLOBAL::hex = sub { 1; };
73 \& }
74 \&
75 \& print hex("0x50"),"\en"; # prints 1
76 \& print CORE::hex("0x50"),"\en"; # prints 80
77 \& CORE::say "yes"; # prints yes
78 \&
79 \& BEGIN { *shove = \e&CORE::push; }
80 \& shove @array, 1,2,3; # pushes on to @array
81 .Ve
82 .SH DESCRIPTION
83 .IX Header "DESCRIPTION"
84 The \f(CW\*(C`CORE\*(C'\fR namespace gives access to the original built\-in functions of
85 Perl. The \f(CW\*(C`CORE\*(C'\fR package is built into
86 Perl, and therefore you do not need to use or
87 require a hypothetical "CORE" module prior to accessing routines in this
88 namespace.
89 .PP
90 A list of the built\-in functions in Perl can be found in perlfunc.
91 .PP
92 For all Perl keywords, a \f(CW\*(C`CORE::\*(C'\fR prefix will force the built\-in function
93 to be used, even if it has been overridden or would normally require the
94 feature pragma. Despite appearances, this has nothing to do with the
95 CORE package, but is part of Perl\*(Aqs syntax.
96 .PP
97 For many Perl functions, the CORE package contains real subroutines. This
98 feature is new in Perl 5.16. You can take references to these and make
99 aliases. However, some can only be called as barewords; i.e., you cannot
100 use ampersand syntax (\f(CW&foo\fR) or call them through references. See the
101 \&\f(CW\*(C`shove\*(C'\fR example above. These subroutines exist for all keywords except the following:
102 .PP
103 \&\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,
104 \&\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,
105 \&\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,
106 \&\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,
107 \&\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,
108 \&\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,
109 \&\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
110 .PP
111 Calling with
112 ampersand syntax and through references does not work for the following
113 functions, as they have special syntax that cannot always be translated
114 into a simple list (e.g., \f(CW\*(C`eof\*(C'\fR vs \f(CWeof()\fR):
115 .PP
116 \&\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,
117 \&\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
118 .SH "OVERRIDING CORE FUNCTIONS"
119 .IX Header "OVERRIDING CORE FUNCTIONS"
120 To override a Perl built\-in routine with your own version, you need to
121 import it at compile\-time. This can be conveniently achieved with the
122 \&\f(CW\*(C`subs\*(C'\fR pragma. This will affect only the package in which you\*(Aqve imported
123 the said subroutine:
124 .PP
125 .Vb 3
126 \& use subs \*(Aqchdir\*(Aq;
127 \& sub chdir { ... }
128 \& chdir $somewhere;
129 .Ve
130 .PP
131 To override a built\-in globally (that is, in all namespaces), you need to
132 import your function into the \f(CW\*(C`CORE::GLOBAL\*(C'\fR pseudo\-namespace at compile
133 time:
134 .PP
135 .Vb 5
136 \& BEGIN {
137 \& *CORE::GLOBAL::hex = sub {
138 \& # ... your code here
139 \& };
140 \& }
141 .Ve
142 .PP
143 The new routine will be called whenever a built\-in function is called
144 without a qualifying package:
145 .PP
146 .Vb 1
147 \& print hex("0x50"),"\en"; # prints 1
148 .Ve
149 .PP
150 In both cases, if you want access to the original, unaltered routine, use
151 the \f(CW\*(C`CORE::\*(C'\fR prefix:
152 .PP
153 .Vb 1
154 \& print CORE::hex("0x50"),"\en"; # prints 80
155 .Ve
156 .SH AUTHOR
157 .IX Header "AUTHOR"
158 This documentation provided by Tels <nospam\[email protected]> 2007.
159 .SH "SEE ALSO"
160 .IX Header "SEE ALSO"
161 perlsub, perlfunc.