Below are some of the most commonly used functions in Perl script programming. This is not meant to be a reference manual; to get the format you can use the man perl command:<br /><br /><br />Los enlaces son solo para miembros. Registrate o iniciá sesión<br /><br /><br />abs: returns the absolute value of the given expression.<br />chmod: changes the permissions of the given files.<br />chop: trims and returns the last character of a string.<br />chown: changes the owner of the given files.<br />close : closes a file.<br />cos: returns the cosine of the given angle in radians.<br />defined: used to check whether a variable, format, subroutine, etc. exists.<br />delete: deletes a value from an associative array via its key.<br />die: prints a message passed as a parameter to standard error output when an error occurs while executing a statement.<br />eof: returns true if at the end of the given file.<br />eval: evaluates the given expression as if it were a small Perl program.<br />exec: executes whatever we pass as a parameter and exits the program.<br />exit: makes us exit the Perl script, returning the value passed as an argument to the operating system.<br />exp: returns the number e raised to the power passed as a parameter.<br />fileno: returns the descriptor of the file handle passed as a parameter.<br />fork: makes a fork call.<br />getc: reads the next character from the specified file.<br />hex: returns the decimal value of the hexadecimal number passed as a parameter.<br />index: returns the position of the first occurrence of one string within another.<br />int: returns the integer part of the parameter passed.<br />join: joins the strings passed as arguments with a separator also passed as an argument.<br />keys: returns all the keys of an associative array.<br />length: returns the length in characters of the parameter passed.<br />local: declares the variables passed as arguments as local.<br />log: returns the logarithm of the given number.<br />mkdir: creates a directory at the given path.<br />oct: returns the decimal value of the octal number passed as a parameter.<br />open: opens the given file, associating it with a file handle also specified as a parameter.<br />pop: returns and removes the last element of the given array.<br />print: displays the given expression on standard output or in the specified file.<br />push: adds the given value to the end of the array passed as a parameter.<br />rand: returns a random number between 0 and the value passed as an argument.<br />read: reads a certain number of characters from the file passed as an argument.<br />rename: used to rename a file.<br />require: used to include external code in our script.<br />return: returns a value from a subroutine.<br />rmdir: deletes a directory.<br />seek: positions a file pointer at a given location.<br />select: used to select the file handle that will be used by default for the output of commands or functions that do not specify a particular file handle as a parameter.<br />shift: returns the first value of the given array, then removes it.<br />sin: returns the sine of the given angle in radians.<br />sleep: causes the Perl script to pause for the specified number of seconds.<br />sort: sorts the given array.<br />split: splits a string into substrings according to the specified separator.<br />sqrt: returns the square root of the given number.<br />system: same as exec but does not exit the Perl script.<br />tell: returns the current position of the file pointer of the specified file handle.<br />values: returns all the values of the given associative array.<br />write: writes a formatted record to the file associated with that format.<br /><br />I hope this helps, regards.<br /><br /><br />Source:Perl-rules.mx
🌐 This is an automatic translation of a topic from Underc0de, the largest Spanish-speaking hacking and IT community. Read the original (Spanish) and reply →
Cita de: Dragora en Enero 06, 2019, 01:01:06 AMBelow are some of the most commonly used functions in Perl script programming. This is not meant to be a reference manual; to get the format you can use the man perl command:
Los enlaces son solo para miembros. Registrate o iniciá sesión
abs: returns the absolute value of the given expression.
chmod: changes the permissions of the given files.
chop: trims and returns the last character of a string.
chown: changes the owner of the given files.
close : closes a file.
cos: returns the cosine of the given angle in radians.
defined: used to check whether a variable, format, subroutine, etc. exists.
delete: deletes a value from an associative array via its key.
die: prints a message passed as a parameter to standard error output when an error occurs while executing a statement.
eof: returns true if at the end of the given file.
eval: evaluates the given expression as if it were a small Perl program.
exec: executes whatever we pass as a parameter and exits the program.
exit: makes us exit the Perl script, returning the value passed as an argument to the operating system.
exp: returns the number e raised to the power passed as a parameter.
fileno: returns the descriptor of the file handle passed as a parameter.
fork: makes a fork call.
getc: reads the next character from the specified file.
hex: returns the decimal value of the hexadecimal number passed as a parameter.
index: returns the position of the first occurrence of one string within another.
int: returns the integer part of the parameter passed.
join: joins the strings passed as arguments with a separator also passed as an argument.
keys: returns all the keys of an associative array.
length: returns the length in characters of the parameter passed.
local: declares the variables passed as arguments as local.
log: returns the logarithm of the given number.
mkdir: creates a directory at the given path with Los enlaces son solo para miembros. Registrate o iniciá sesión.
oct: returns the decimal value of the octal number passed as a parameter.
open: opens the given file, associating it with a file handle also specified as a parameter.
pop: returns and removes the last element of the given array.
print: displays the given expression on standard output or in the specified file.
push: adds the given value to the end of the array passed as a parameter.
rand: returns a random number between 0 and the value passed as an argument.
read: reads a certain number of characters from the file passed as an argument.
rename: used to rename a file.
require: used to include external code in our script.
return: returns a value from a subroutine.
rmdir: deletes a directory.
seek: positions a file pointer at a given location.
select: used to select the file handle that will be used by default for the output of commands or functions that do not specify a particular file handle as a parameter.
shift: returns the first value of the given array, then removes it.
sin: returns the sine of the given angle in radians.
sleep: causes the Perl script to pause for the specified number of seconds.
sort: sorts the given array.
split: splits a string into substrings according to the specified separator.
sqrt: returns the square root of the given number.
system: same as exec but does not exit the Perl script.
tell: returns the current position of the file pointer of the specified file handle.
values: returns all the values of the given associative array.
write: writes a formatted record to the file associated with that format.
I hope this helps, regards.
Source:Perl-rules.mx
Hi buddy, thanks for sharing this summary of the most commonly used functions in Perl. It's an excellent introduction to some of the language's key functions, especially for those who are just starting out or need a quick reminder of how to use certain features. The structure is clear, but here are some additional points that could complement your description:
Additional documentation: As you mention, the most detailed reference is found in the man perl command. You can also access Perl's online documentation, which is very thorough and will help you understand in detail how these functions work and what additional options they have.
Contexts in Perl: When using functions like print, keys, or values, remember that Perl works in two contexts: scalar and list. Some functions can return different results depending on whether they are used in a scalar or a list context, which is an important feature of Perl.
Use of local and my: In addition to local, which makes a variable local within a block or function, it's important to mention that my also declares local variables, but in a more restrictive way and within a more limited scope.
String manipulation functions: If you're working with string manipulation, functions like substr, index, or lc/uc can also be quite useful. They let you extract substrings, search for strings within others, or convert text to lowercase or uppercase.
Efficiency: Although functions like eval and exec are powerful, you should be careful when using them, since they can affect security or performance if not handled properly.
Overall, it's a quite useful summary and covers many of the essential functions. If you'd like to dig deeper into any of them or have any questions about their implementation, don't hesitate to ask!
Regards!