CORE(3perl)
β¨ NAME β¨
CORE β the namespace where Perl's core routines live, and yes bestie it's giving main character energy π
πΈ SYNOPSIS πΈ
BEGIN {
*CORE::GLOBAL::hex = sub { 1; };
}
print hex("0x50"),"\n"; # prints 1
print CORE::hex("0x50"),"\n"; # prints 80
CORE::say "yes"; # prints yes
BEGIN { *shove = \&CORE::push; }
shove @array, 1,2,3; # pushes on to @array
π¦ DESCRIPTION π¦
okay so the CORE namespace is basically your backstage pass π to Perl's original built-in functions. The CORE package is baked right into Perl itself, so bestie you literally do not need to use or require some hypothetical CORE module before you can reach in and grab routines from this namespace. it's already there. no cap. β¨
wanna know which functions are built in? the full list lives over in perlfunc π
so here's the tea for all Perl keywords: if you slap a CORE:: prefix on the front, it forces the built-in function to be used β even if it's been overridden, or even if it would normally need the feature pragma. π«Ά And likeβ¦ despite how it looks? this has absolutely nothing to do with the CORE package. it's part of Perl's syntax. iykyk π
For many Perl functions, the CORE package actually contains real subroutines. this feature is new in Perl 5.16 β You can take references to these and make aliases, which is lowkey iconic. These subroutines exist for all keywords except the following π
__DATA__,__END__,and,cmp,default,do,dump,else,elsif,eq,eval,for,foreach,format,ge,given,goto,grep,gt,if,last,le,local,lt,m,map,my,ne,next,no,or,our,package,print,printf,q,qq,qr,qw,qx,redo,require,return,s,say,sort,state,sub,tr,unless,until,use,when,while,x,xor,y
mind the gap bestie π that's the whole list, don't come for me.
However π some CORE subroutines can only be aliased and called as barewords. that means no ampersand syntax (&foo) and no calling them through references β periodt. peep the shove example up in the SYNOPSIS for the vibe. These are:
__CLASS__,chomp,chop,defined,delete,eof,exec,exists,lstat,split,stat,system,truncate,unlink
and why are they like this? because they have special syntax that can't always be translated into a simple list (like, eof versus eof(), hello π) or they have other special behavior. it's just built different, fr fr.
π OVERRIDING CORE FUNCTIONS π
so you wanna replace a Perl built-in with your own version? obsessed. π To do that, you need to import it at compile-time. the convenient way to pull this off is with the subs pragma β¨ and heads up β this will only affect the package where you imported that subroutine. just that one. no crossover:
use subs 'chdir';
sub chdir { ... }
chdir $somewhere;
now, if you want to override a built-in globally (as in, across all namespaces, main character on every stage π
), you need to import your function into the CORE::GLOBAL pseudo-namespace at compile time:
BEGIN {
*CORE::GLOBAL::hex = sub {
# ... your code here
};
}
and then your shiny new routine gets called whenever a built-in function is called without a qualifying package:
print hex("0x50"),"\n"; # prints 1
in both of those cases, if you still wanna reach the original, unaltered routine? just use the CORE:: prefix and boom π:
print CORE::hex("0x50"),"\n"; # prints 80
π AUTHOR π
This documentation provided by Tels <nospam-abuse@bloodgate.com> 2007.
π SEE ALSO π
perlsub, perlfunc.
and that's the whole vibe check, bestie π§ go forth and slay those built-ins π
this page was served fresh by perl v5.44.0, dated 2026-10-17 β yes she ate, and yes she knows it π β¨
π¦ where this page comes from
- arch rolling: perl 5.44.0-1 Β· Artistic-1.0-Perl AND GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms