Dive into the dynamic world of Perl programming with our latest blog post! ๐ Whether you're a seasoned Perl guru or just starting your scripting journey, this comprehensive guide to Perl acronyms and keywords is tailored just for you.
๐งฉ Discover the Language's Core: From use to sub, and my to %ENV, we've covered it all! Each term is not just explained; it's brought to life with vibrant emojis that capture the essence of Perl's versatility and charm. ๐ญ
๐ A Learning Journey: This post isn't just informative, it's a visual treat too! We believe learning should be fun, engaging, and easy to grasp. That's why we've sprinkled a dash of emoji magic on each term, making the technical lingo more relatable and memorable. ๐
๐ For the Curious Minds: Ever wondered what bless or chomp really do? Or how about the magic behind $_ or @ARGV? Uncover these mysteries and more as we break down the functionality of each keyword and acronym in a clear, concise, and captivating manner. ๐งโโ๏ธ
๐ก Your Go-To Perl Glossary: Think of this post as your handy Perl glossary, but with a twist! Whether you're debugging a script, writing new code, or brushing up your Perl knowledge, our list is a perfect companion to light up your coding journey. ๐ซ
๐จโ๐ป For Developers, By a Developer: Crafted with love and technical expertise, this post aims to enrich your programming skills and add a spark of joy to your coding sessions. Join us on this exciting adventure through the Perl landscape, emoji style! ๐ข
๐ Ready to Explore? Let's unravel the secrets of Perl together in a way that's never been done before! Happy coding! ๐
Acronym/Keyword | Explanation |
---|---|
AutoLoader | Load subroutines only on demand in Perl ๐๏ธ |
B::Bytecode | Another backend of the Perl compiler, which compiles Perl code into a bytecode format that can be executed by a bytecode engine. This is less commonly used than B::C and serves a more experimental or specialized purpose ๐ |
B::C | A Perl compiler backend that generates C code from Perl code. It's part of the Perl compiler suite and is used for transforming Perl scripts into executable binaries or C source code ๐ |
BEGIN {} | A block that is executed as soon as it is compiled, typically used to set up the environment before the main script runs. This happens at compile time, making it useful for initializing settings or loading modules that affect the compilation of the rest of the script ๐ |
Benchmark | Benchmark running times of Perl code โฑ๏ธ |
BioPerl | A collection of Perl modules for bioinformatics ๐งฌ |
CGI | Provides functions for handling web requests and responses ๐ |
CGI.pm | Standard Perl module for creating and handling CGI scripts ๐ฅ๏ธ |
CPAN | Comprehensive Perl Archive Network, a repository of Perl modules ๐ |
Carp | Alternative warn and die for Perl, better for modules ๐จ |
Catalyst | A popular web application framework for Perl ๐ |
Crypt::SSLeay | OpenSSL support for LWP ๐ก๏ธ |
DATA | Denotes a section where you can put data accessed using the DATA filehandle ๐ |
DBD | Database Driver, a Perl module that implements DBI for a specific database ๐ฝ |
DBI | Database independent interface for accessing databases ๐พ |
Dancer | A lightweight web application framework for Perl ๐ |
Data::Dumper | Stringified Perl data structures, suitable for both printing and eval ๐ |
Devel::Cover | Code coverage metrics for Perl ๐ |
Digest::MD5 | Perl interface to the MD5 Algorithm ๐ |
END | Marks the logical end of the script; any text following it is ignored by the Perl interpreter ๐ |
Encode | Character encoding module for Perl ๐ฃ๏ธ |
Exporter | Implements default import method for Perl modules ๐ฆ |
Getopt::Long | Extended processing of command line options ๐ ๏ธ |
HEREDOC | A syntax for defining multi-line strings, using a custom delimiter to start and end the text block ๐ |
HTML::Parser | Perl module for parsing HTML documents ๐ |
HTTP::Cookies | HTTP cookie jars, for storing cookies ๐ช |
INIT {} | Similar to BEGIN, but it runs just before the runtime phase begins, after all BEGIN blocks have been executed. This is less commonly used but can be handy for initializing environment variables or other setup tasks that need to happen after all compilations are complete but before the main execution ๐ |
IO::File | Provides object-oriented interface to filehandles ๐ |
IO::Socket | Provides object-oriented interface to sockets ๐ |
IO::Socket::INET | Object interface for creating and using sockets in Perl ๐ |
JSON | JavaScript Object Notation, used for data interchange ๐ |
LWP | Library for WWW in Perl, used for web programming ๐ |
LWP::UserAgent | A web user agent class for Perl ๐ต๏ธ |
List::MoreUtils | Provide the stuff missing in List::Util ๐ |
List::Util | General-utility list subroutines for Perl ๐ |
Makefile | Often used in Perl (especially in module distribution), a Makefile is a script used with the make utility to automate the building and installation of Perl modules and applications. It defines how to compile and link the program, run tests, install the modules, etc. ๐ ๏ธ |
Module::CoreList | What modules shipped with versions of Perl? ๐ |
Mojolicious | A next-generation web framework for the Perl programming language ๐งช |
Moose | A modern object-oriented system for Perl ๐ฆ |
Net::FTP | File Transfer Protocol client for Perl ๐ |
Net::SMTP | Simple Mail Transfer Protocol client for Perl ๐ง |
Net::SSH | Secure Shell client for Perl ๐ |
Other switches | Perl has many other command-line switches for various purposes, like -w for enabling warnings, -v for printing the Perl version, -T for taint checks, etc. Each serves a specific purpose in controlling the behavior of the Perl interpreter or the script being executed ๐ง |
PDL | Perl Data Language, for scientific computing with Perl ๐งฎ |
PSGI | Perl Web Server Gateway Interface, a specification for web servers and web applications ๐ช |
Perl Critic | A static source code analyzer for Perl. It's used to enforce coding standards and best practices. Perl Critic reviews your code against a set of policies that are intended to encourage good coding habits ๐ |
Plack | Perl Superglue for Web frameworks and Web Servers, a set of tools for using PSGI stack ๐ ๏ธ |
Pod::Parser | Framework for parsing Perl's Plain Old Documentation format ๐ |
Rex | Remote Execution, used for managing all your boxes from a central point ๐ฎ |
Scalar::Util | General-utility scalar subroutines for Perl ๐ |
Storable | Persistence for Perl data structures ๐พ |
TAP | Test Anything Protocol, a simple text-based interface between testing modules and test harnesses ๐ |
Test::More | Writing tests for Perl modules ๐งช |
Test::Simple | Basic utilities for writing tests in Perl ๐ |
Text::Template | A system for embedding Perl code in text files for dynamic content ๐ |
Tie::File | Access the lines of a disk file via a Perl array ๐ |
Time::HiRes | High-resolution time functions for Perl โฑ๏ธ |
URI | Uniform Resource Identifiers management in Perl ๐ |
XML | eXtensible Markup Language, used for structured data representation ๐ |
YAML | YAML Ain't Markup Language, used for configuration files ๐ |
abs | Returns the absolute value of its argument ๐ |
autovivify | Automatically creates data structures (like hashes or arrays) as needed when accessed ๐ฑ |
binmode | Prepares a filehandle for reading or writing binary data โ๏ธ |
bless | Associates an object with a class in object-oriented Perl ๐ |
caller | Returns the context of the current subroutine call โ๏ธ |
carton | A Perl module dependency manager, similar to Bundler in Ruby. It keeps track of the Perl module dependencies for your Perl project and ensures all dependencies are met, making it easier to manage complex Perl projects ๐ฆ |
chdir | Changes the current working directory ๐ช |
chmod | Changes the permissions of a list of files ๐ |
chomp | Removes the newline character from the end of a string (if present) โ๏ธ |
chop | Removes the last character from a string โ๏ธ๐ |
chown | Changes the owner (and optionally the group) of a list of files ๐ฅ |
chr | Returns the character represented by the ASCII value ๐ |
close | Closes an open filehandle ๐ |
continue | A block that always runs at the end of a given-when block ๐ |
cos | Returns the cosine of its argument (in radians) ๐ |
cpanfile | A format for specifying Perl module dependencies for an application. It lists the required modules and their versions, providing a declarative way of managing dependencies for Perl projects ๐ |
cpanm | Short for "cpanminus," it's a script to get, unpack, build, and install modules from CPAN. It's known for being more lightweight and having fewer dependencies compared to the traditional CPAN module installer ๐ ๏ธ |
default | A block within a given statement that runs if no when block matches โ |
defined | Checks if a variable has a defined value โ |
delete | Removes a key-value pair from a hash ๐๏ธ |
die | Prints a message to the standard error output and exits the current script ๐ |
do | Executes a block of code or a file ๐โโ๏ธ |
each | Produces a 2-element list consisting of the key and value for each hash element ๐ซ |
eof | Checks if the filehandle has reached the end of the file ๐ |
eval | Executes a string of Perl code at runtime ๐งโโ๏ธ |
exec | Replaces the current script with a new process ๐ |
exists | Checks if a specified key exists in a hash ๐ง |
exp | Returns e (the natural logarithm base) to the power of its argument ๐ฅ |
fileno | Returns the file descriptor for a filehandle ๐ข |
flock | Locks or unlocks a filehandle ๐ |
foreach | Loops over a list of values, assigning each value in turn to a variable ๐ |
given | A switch statement, similar to switch in other languages ๐ |
glob | Returns a list of filenames matching a wildcard pattern ๐ |
gmtime | Works like localtime but the returned time is in GMT ๐ |
goto LABEL | Jumps to a named label within the same scope ๐ท๏ธ |
grep | Filters a list of values through a condition ๐ต๏ธโโ๏ธ |
hex | Converts a string representing a hexadecimal number to its decimal value ๐ |
import | Brings symbols from a module into the current namespace โฌ๏ธ |
index | Finds the position of one string within another ๐ |
int | Returns the integer portion of a number ๐งฎ |
join | Joins an array into a string using a delimiter ๐ |
keys | Returns a list of all the keys of a hash ๐ |
last | Exits the nearest enclosing loop immediately ๐ช |
lc | Returns a lowercase version of its argument ๐ก |
lcfirst | Lowercases the first character of a string ๐ค |
length | Returns the length of a string ๐ |
link | Creates a hard link between two files ๐ |
local | Temporarily overrides the value of a global variable within a block ๐ ๏ธ |
localtime | Converts a time (seconds since the epoch) to a 9-element list ๐ |
log | Returns the natural logarithm of its argument ๐ |
lstat | Like stat, but for symbolic links ๐ |
map | Transforms a list by applying a block of code to each element ๐บ๏ธ |
mkdir | Creates a new directory ๐ |
my | Declares a lexically scoped variable, local to the block in which it is defined ๐ |
next | Jumps to the next iteration of the nearest enclosing loop โก๏ธ |
no | Unloads a Perl module or negates effects of a previous 'use' statement ๐ซ |
nytprof | Short for "NYTProf," it's a powerful and versatile Perl profiler that provides detailed and accurate information about where a Perl program spends its time. It's useful for optimizing code performance โฑ๏ธ |
oct | Converts a string representing an octal number to its decimal value 8๏ธโฃ |
open | Opens a file for reading, writing, or appending ๐ |
ord | Returns the ASCII value of the first character in the string ๐ข |
our | Declares a globally scoped variable, accessible across different packages ๐ |
pack | Packs a list into a binary structure ๐ฆ |
package | Declares a separate namespace for variables and subroutines ๐ฆ |
perl -e | Executes a line of Perl code from the command line. It's often used for quick Perl scripts or one-liners that perform a specific task in the shell ๐ฅ๏ธ |
perl-I | Adds a directory to the list of directories to be searched for Perl modules. It's useful for including custom libraries or modules that are not in the standard @INC paths ๐ |
perl-M | Allows you to 'use' a module from the command line. For example, perl -MData::Dumper -e '...' is like adding use Data::Dumper; at the beginning of the Perl script ๐ |
perl-c | Checks the syntax of a Perl script without executing it. It's useful for quickly validating a script's syntax ๐ต๏ธ |
perl-d | Starts the Perl debugger, which allows you to step through a Perl script, set breakpoints, and inspect variables for debugging purposes ๐ |
perl-e | Executes a line of Perl code from the command line. It's often used for quick Perl scripts or one-liners that perform a specific task in the shell ๐ฅ๏ธ |
perldoc | Tool for reading Perl documentation ๐ |
perlenv | A command that helps you manage the environment in which Perl runs. It can be used to set various Perl-related environment variables that affect how Perl scripts are executed ๐ |
plackup | A command to run PSGI applications using Plack. Plack provides a unified interface for web application frameworks and web servers in Perl. plackup makes it easy to run and test PSGI applications with various backend servers ๐ |
pop | Removes and returns the last element of an array ๐ฟ |
Outputs a list of strings to a filehandle or the standard output ๐จ๏ธ | |
printf | Prints a formatted string ๐จ๏ธ |
push | Adds elements to the end of an array โ |
quotemeta | Escapes non-alphanumeric characters in a string ๐ |
rand | Returns a random fractional number between 0 and its argument ๐ฒ |
read | Reads a block of information from a filehandle ๐ |
readlink | Determines the target of a symbolic link โก๏ธ |
redo | Restarts the current iteration of the loop without evaluating the condition again โฉ๏ธ |
ref | Returns the reference type of its argument (if a reference) or an empty string ๐ |
rename | Renames a file or moves it to a different directory โ๏ธ |
require | Loads a Perl module at runtime, but only once ๐ฆ |
reverse | Reverses a list or a string โ๏ธ |
rindex | Finds the last position of one string within another ๐ |
rmdir | Removes a directory ๐๏ธ |
scalar | Forces scalar context on the given expression or returns the size of an array โ๏ธ |
seek | Moves the filehandle's read/write position to a different location in the file ๐ |
select | Sets or gets the default filehandle for output or does I/O multiplexing ๐ |
shift | Removes and returns the first element of an array or @_ in a subroutine ๐ |
sin | Returns the sine of its argument (in radians) ๐ |
sort | Sorts a list of values ๐ |
splice | Removes and replaces a portion of an array โ๏ธ๐ |
split | Splits a string into an array based on a delimiter ๐ช |
sprintf | Formats and returns a formatted string ๐๏ธ |
sqrt | Returns the square root of its argument ๐ฒ |
srand | Seeds the random number generator ๐ฑ |
starman | A high-performance, pre-forking Perl PSGI web server. It's typically used with Plack and is designed for running high-performance production web apps. Starman is known for its speed and efficiency, especially in handling concurrent connections ๐ |
stat | Returns a list of status information about a file ๐ |
state | Declares a state variable that maintains its value between calls ๐ |
strict | Forces you to declare variables before you use them in Perl ๐ซ |
sub | Defines a subroutine or function in Perl ๐ ๏ธ |
substr | Extracts a substring from a string ๐ช |
symlink | Creates a symbolic link between two files โฐ |
system | Executes an external command and waits for it to finish ๐ฅ๏ธ |
tell | Returns the current position of the filehandle's read/write pointer ๐ |
tie | Associates a variable with a package class for special behaviors ๐ |
tied | Returns the package name of a tied variable, if it is tied ๐ of a string (if present) โ๏ธ |
time | Returns the current time in seconds since the Unix epoch โฑ๏ธ |
uc | Returns an uppercase version of its argument ๐ |
ucfirst | Uppercases the first character of a string ๐ก |
umask | Sets or gets the file mode creation mask ๐ฎโโ๏ธ |
undef | Sets a variable to an undefined value or returns an undefined value ๐ซ |
unless | Conditional statement that executes the block if the condition is false โ |
unlink | Deletes a list of files ๐๏ธ |
unpack | Unpacks a binary structure into a list ๐ค |
unshift | Adds elements to the beginning of an array ๐ |
untie | Breaks the association created by tie ๐งถ |
use | Loads a Perl module; akin to 'import' in other languages ๐ |
values | Returns a list of all the values of a hash ๐ |
vec | Treats a string as a vector of unsigned integers ๐ |
wantarray | Returns true if the current subroutine expects a list value ๐ |
warn | Outputs a warning message to the standard error output โ ๏ธ |
warnings | Enable or disable warnings for Perl ๐จ |
when | A block within a given statement that runs if its condition is true โ |
Symbol | Explanation |
---|---|
!~ | Negated binding operator. It's the opposite of =~ , used for when a match is not wanted ๐โ |
# | In Perl, the hash (# ) character is used to denote a comment. Everything following # on a line is ignored by the Perl interpreter ๐ |
$ | Scalar variable prefix, used before variable names for single values like numbers or strings ๐ฐ |
$! | Contains the current value of the operating system's error message corresponding to $! (errno). Useful for error handling and reporting ๐จ |
$# | Array prefix for accessing the last index of an array ๐ |
$#array | Index of the last element in an array. E.g., $#array gives the last index of @array ๐ |
$$ | Current process ID (PID) of the Perl script being executed. Useful for system operations and process management ๐ |
$% | Current page number of the currently selected output channel. Used in format-writing to control page numbers ๐๐ข |
$, | The output field separator for the print function. It's used to separate the fields when printed out ๐จ๏ธ |
$- | Lines left on the page of the currently selected output channel. Useful for controlling page breaks in reports ๐โ |
$. | Current line number for the last filehandle accessed. Useful for error messages or tracking file reading progress ๐ข |
$/ | The input record separator. It's used to determine how Perl reads input record-wise, typically set to newline by default ๐ |
$0 | Special variable containing the name of the script being executed ๐ |
$: | The current set of characters after which a string can be broken to fill continuation fields in formats ๐ |
$; | The subscript separator for multi-dimensional array emulation. It's used when simulating multi-dimensional arrays with hashes ๐ |
$= | Current page length (format lines-per-page) of the currently selected output channel. Adjusts the length of pages in formatted reports ๐ |
$? | The status returned by the last pipe close, backtick command, or system operator. Useful for checking the success of system commands ๐ฆ |
$@ | Contains the error message (if any) from the last eval command. It's Perl's way of handling exceptions or runtime errors ๐ |
$ARGV | Current file name when reading from <> . In a loop like while (<>){} , $ARGV contains the name of the current file being read ๐ |
$AUTOLOAD | A special subroutine that is called when an undefined subroutine is invoked. Useful in object-oriented Perl for dynamic method handling ๐ |
$ENV{VAR} | Accesses an environment variable named VAR . %ENV is the hash containing environment variables, and $ENV{VAR} accesses a specific one ๐ |
$SIG{__DIE__} | A signal handler for intercepting fatal errors (die statements) ๐ซ |
$SIG{__WARN__} | A signal handler for intercepting warnings (warn statements) โ ๏ธ |
$[` | A special variable that sets the index of the first element in an array or string. Changing this is generally discouraged ๐ข |
$^ | The name of the top-of-page format for the currently selected output channel. Used in formatted reporting for headers ๐๐ |
$^A | The accumulator for the write function. It's used internally by the write function for formatting output ๐ |
$^D | The debug flags. You can set this to enable certain debugging features in Perl ๐๐ |
$^F | The maximum system file descriptor, ordinarily 2. System file descriptors greater than $^F are not closed during an exec โ๏ธ |
$^H | Internal variable for compiler hints. It's used by Perl to convey hints to the compiler for certain optimizations ๐ |
$^I | The in-place edit operator. If set, Perl will edit files in place when using the diamond operator <> โ๏ธ๐ |
$^L | The output page separator. It's used in formatted output to separate pages ๐โก๏ธ |
$^M | A variable that can be set to a block of memory for Perl to use when it runs out of memory. It's a sort of emergency memory pool ๐ |
$^O | The name of the operating system under which the Perl script is running. Helpful for writing OS-specific code ๐ฅ๏ธ |
$^P | Internal variable controlling debugging and profiling of Perl scripts. It's useful for enabling certain debugging behaviors ๐ |
$^R | The result of evaluation of the last successful (??{ code }) regular expression assertion. This is a bit esoteric and used in complex regex patterns ๐งฉ |
$^S | True if within an eval call. It's used to check if code is being executed within an eval block ๐ |
$^T | The script's start time (epoch time). Useful for timing operations or calculating script duration โฑ๏ธ |
$^V | The Perl version. It's used to check or display the version of Perl the script is running under ๐ |
$^W | The global warning flag, similar to using the -w command-line flag. Controls whether warnings are enabled globally โ ๏ธ |
$^X | The path to the Perl binary that's executing the current script. Useful for invoking Perl scripts or modules dynamically ๐ ๏ธ |
$_ | The default variable of Perl. It's used implicitly by many functions and operators ๐ |
$_[0] | Accesses the first argument to a subroutine inside the subroutine ๐ฅ |
$~ | The name of the current report format for the currently selected output channel. Defines how formatted output should look ๐ |
% | Hash (associative array) variable prefix, used for key-value paired structures ๐บ๏ธ |
%ENV | Hash containing the current environment variables. It's a direct interface to the environment from a Perl script ๐ |
%INC | Hash that shows which Perl modules have been loaded via do , require , or use , along with their paths ๐ |
%SIG | Hash used for setting signal handlers for various signals (like INT, TERM, etc.). Allows Perl scripts to handle signals gracefully ๐ฆ |
Reference operator, used to create a reference to a variable, array, hash, or subroutine (like \@array ) ๐ |
|
++ | Increment operator. Increases the value of a variable by one (like $x++ ) โ |
-- | Decrement operator. Decreases the value of a variable by one (like $x-- ) โ |
-> | Arrow operator, used for method calls or dereferencing references (like $object->method() or $arrayref->[0] ) ๐ |
.. | Range operator. Creates a list of values in a range (like 1..10 ) ๐ |
/x, /i, /m, /s | Regular expression modifiers. /x for extended formatting, /i for case-insensitive, /m for multi-line, and /s for treating the string as a single line ๐งฉ |
<> | The diamond operator, used for file input. It reads from standard input or files specified in @ARGV ๐ |
Used to read from a filehandle. In a while loop, while (<FILEHANDLE>) { ... } reads a file line by line ๐ |
|
=> | The "fat comma" operator, mainly used for initializing hashes. It's similar to the comma but provides better readability โก๏ธ |
=~ | Binding operator. It's used to bind a string to a regular expression match or substitution ๐ |
?: (Ternary) | The ternary conditional operator, a compact form of if-else statement (condition ? true_expr : false_expr) ๐ค |
@ | Array variable prefix, used before names of arrays (lists of scalars) ๐ |
@ARGV | Array containing the command-line arguments to the script. Does not include the script name, which is held in $0 ๐ |
@INC | Array containing the paths in which Perl looks for modules. It's like the environment variable PATH but for Perl modules ๐ |
@ISA | An array in a package that lists its parent classes, used in Perl's object-oriented programming for defining inheritance relationships ๐งฌ |
@_ | Array of parameters passed to a subroutine. In a subroutine, $_[0] , $_[1] , etc., represent the first, second, and subsequent arguments ๐ฆ |
END | Indicates the logical end of the script. Any text following this token is ignored by the Perl interpreter ๐ |
__DATA__ | Marks a section of the script for embedded data, accessible via the DATA filehandle ๐ |
__FILE__ | A special literal that returns the name of the current file. Useful in modules to reference the current file name ๐ |
__LINE__ | A special literal that returns the current line number in the source file. Handy for debugging and error messages ๐ข |
__PACKAGE__ | A special literal that returns the name of the current package. Useful in modular Perl code for identifying the current package ๐ฆ |
local | Temporarily gives a global variable a temporary value within a block of code. It's used to locally override global variables ๐ ๏ธ |
m// | Match operator, used for regular expression matching in Perl (like m/regex/ ) ๐ |
q//, qq//, qx// | Variants of the quote operators. q// is for single quotes, qq// for double quotes, and qx// for executing commands ๐๏ธ |
qw// | Quotes words operator. It's a way to create a list or array without using quotes and commas (like qw/this is a list/ ) ๐ |
s/// | Substitute operator, used for replacing text via a regular expression (like s/old/new/ ) ๐ |
tr/// | Transliterate operator, used for character-by-character replacement (like tr/abc/xyz/ ) ๐ |
x | String repetition operator. E.g., 'foo' x 3 produces foofoofoo ๐ |
y/// | Another form of the transliterate operator, similar to tr/// (like y/abc/xyz/ ) ๐ |
Switch | Explanation |
---|---|
-f | Tests if a specified file is a plain file. In a Perl script, you'd use it as -f $filename to check if $filename is a regular file (not a directory or a special file) ๐ |
-d | Tests if a specified file is a directory. In Perl, you'd use -d $dirname to check if $dirname is a directory ๐ |
-e | Checks if a file or directory exists. if (-e $file_or_dir) will be true if $file_or_dir exists in the filesystem ๐ |
-s | Returns the size of a file if it's not empty; otherwise returns false (undefined). It's useful for checking if a file is non-empty and determining its size ๐ |
-r | Checks if a file is readable by the current user or process. Useful for ensuring that a script can read a file before attempting to open it ๐ |
-w | Tests if a file is writable by the current user or process. This is important for scripts that need to modify or write to files โ๏ธ |
-x | Checks if a file is executable. This is particularly useful when dealing with scripts or programs that you might want to execute ๐ |
-z | Tests if a file is empty (zero size). if (-z $filename) will be true if $filename has no content ๐ซ |
-T | Heuristically tests if a file is a text file. This can be handy for distinguishing text files from binary files in scripts ๐ |
-B | The opposite of -T ; it checks if a file is a "binary" file. Useful for filtering out non-text files in a set of files ๐๏ธ |
-M | Returns the age of a file (in days) since it was last modified. This is useful for scripts that need to process files based on their modification dates ๐ |
-A | Similar to -M , but returns the age of a file since it was last accessed. This can be used for maintenance scripts that clean up or archive files based on access times ๐ |
-C | Returns the age of a file (in days) since its inode change time. This could be used to monitor when file metadata or ownership has changed ๐ |
F-Spec | Explanation |
---|---|
%s | Formats and prints the corresponding argument as a string. If the argument is not a string, it's converted to string form first ๐ |
%d | Formats and prints the corresponding argument as a signed decimal integer. It's used for numbers ๐ข |
%u | Formats and prints the corresponding argument as an unsigned decimal integer ๐ |
%f | Formats and prints the corresponding argument as a floating-point number. It can include precision specifiers to control the number of digits after the decimal point ๐ |
%e | Formats and prints the corresponding argument in scientific notation (e.g., 1.23e+02) ๐ฌ |
%E | Similar to %e but uses an uppercase E for the exponent (e.g., 1.23E+02) ๐ฌ๐ |
%g | Uses either %f or %e formatting, whichever is more compact for the given number and precision ๐ |
%G | Similar to %g but uses %E instead of %e where applicable ๐๐ |
%x | Formats and prints the corresponding argument as a hexadecimal number (with lowercase letters a-f) ๐ |
%X | Formats and prints the corresponding argument as a hexadecimal number (with uppercase letters A-F) ๐๐ |
%o | Formats and prints the corresponding argument as an octal number ๐ข |
%b | Formats and prints the corresponding argument as a binary number (not standard in Perl but can be implemented) ๐ฅ๏ธ |
%c | Formats and prints the corresponding argument as a character (using its ASCII value) ๐ |
%% | Prints a literal % character. This is used when you need to include a percent sign in your output ๐ฃ |
%p | Prints the corresponding argument as a pointer (in hexadecimal form). This is more relevant in C and other lower-level languages where pointers are used directly ๐ |
%n | Not a way to print something, but a way to store the number of characters printed so far into the corresponding argument variable (not commonly used in Perl) ๐ |