Found 152 Articles for PERL

How to compare two arrays for equality in Perl?

Mukul Latiyan
Updated on 26-Dec-2022 16:44:26
In Perl, there are two ways to check if two arrays are equal. We can compare two arrays in Perl with the help of "Storable freeze" function or by creating our own custom function. In this tutorial, we will explore both these approaches with the help of examples. Example 1 Let's first explore the "Storable freeze" code and understand how it works. Consider the code shown below. use Storable qw/freeze/; use strict; $Storable::canonical = 1; my @countriesOne = ('India', 'China', 'Russia', 'USA', 'Germany'); my @countriesTwo = ('India', 'China', 'Russia', 'USA', 'Germany'); my @countriesThree = ... Read More

How to check if a variable has a numeric value in Perl?

Mukul Latiyan
Updated on 26-Dec-2022 16:42:44
Suppose we get a variable at runtime in Perl and we want to check if the value that it contains is numeric or not, then we can use the two approaches shown in this tutorial. We will use two simple examples to demonstrate how it works. Example  The most basic approach is to use the length and do keywords and then ignore the warnings. Consider the code shown below for the same. $x = 100; if (length(do { no warnings "numeric"; $x & "" })){ print "x is numeric"; } else { print ... Read More

How to check if a Perl hash already contains a key?

Mukul Latiyan
Updated on 26-Dec-2022 16:40:11
Let's consider a scenario where we would want to know if a Perl hash already contains a key or not. To do so in Perl, we can use the exists() function. In this tutorial, we will explore the exists function with the help of two examples. The exists() Function in Perl In Perl, the exists() function checks whether a particular element exists or not in an array or a hash. If the requested element appears in the input array or hash, this function returns "1", else it returns "0". Example 1 Consider the code shown below. In this example, we ... Read More

How to check if a file exists in Perl?

Mukul Latiyan
Updated on 14-Mar-2023 18:05:09
In this tutorial, we will take a couple of examples and demonstrate how you can if a file exists or not, with the help of Perl. Let's suppose we have a simple text file called "sample.txt" with the following data − This is a sample txt file that contains some content inside it. TutorialsPoint is simply amazing! We will use a Perl code to check whether this file exists or not. Example 1 The most basic approach to check whether a file exists or not is to use the "-e" flag and then pass the name of the file. ... Read More

How to check if a Perl array contains a particular value?

Mukul Latiyan
Updated on 26-Dec-2022 16:28:21
In Perl, we can check whether an array contains a particular value or not with the help of the "grep" keyword. The grep function in Perl is used to filter the input supplied in the function as a parameter out of the list of items. Similar to Linux, it uses the given input to find the matching value. The grep() Method "grep" is a built-in function in Perl, we can pass our regular expression inside this function. It will check the input for matching values and return a list based on whether the condition is true or false. Syntax As ... Read More

How to break out of a loop in Perl?

Mukul Latiyan
Updated on 26-Dec-2022 16:23:22
In most programming languages, we can use the "break" keyword to break out of any type of loop. In Perl too, we have the "break" keyword available, but the keyword that is used the most to break out of a loop is the "last" keyword. The "last" Statement in Perl The "last" statement is used in Perl loops to exit a loop immediately; it is the equivalent of the "break" statement in C/C++ and Java. In practice, you often use the "last" statement to exit a loop if one of the conditions is met, for example, you find an ... Read More

Difference between CGI and Perl

Pradeep Kumar
Updated on 25-Jul-2022 09:20:45
The acronym CGI and the programming language Perl are frequently confused for one another. Both of these are frequently referred to as "CGI Perl." These two terms refer to two distinct concepts. Your comprehension of both of these terms will improve if you are aware of the unique characteristics that distinguish each of them.What is CGI?CGI, or Common Gateway Interface, is a rule set that governs how data can be transferred between web servers and scripts written in programming languages. The use of CGI programmes enables the sending of data in a variety of formats, including audio clips, photographs, documents, ... Read More

What is POD in Perl?

Mohd Mohtashim
Updated on 02-Dec-2019 10:53:16
Pod is a simple-to-use markup language used for writing documentation for Perl, Perl programs, and Perl modules. There are various translators available for converting Pod to various formats like plain text, HTML, man pages, and more. Pod markup consists of three basic kinds of paragraphs −Ordinary Paragraph − You can use formatting codes in ordinary paragraphs, for bold, italic, code-style , hyperlinks, and more.Verbatim Paragraph − Verbatim paragraphs are usually used for presenting a codeblock or other text which does not require any special parsing or formatting, and which shouldn't be wrapped.Command Paragraph − A command paragraph is used for ... Read More

The kill() Function in Perl

Mohd Mohtashim
Updated on 02-Dec-2019 10:51:53
Perl kill('KILL', (Process List)) function can be used to terminate a pseudo-process by passing it the ID returned by fork().Note that using kill('KILL', (Process List)) on a pseudo-process() may typically cause memory leaks, because the thread that implements the pseudo-process does not get a chance to clean up its resources.You can use kill() function to send any other signal to target processes, for example following will send SIGINT to a process IDs 104 and 102 −#!/usr/bin/perl kill('INT', 104, 102); 1;

The fork() Function in Perl

Mohd Mohtashim
Updated on 02-Dec-2019 10:49:35
Perl provides a fork() function that corresponds to the Unix system call of the same name. On most Unix-like platforms where the fork() system call is available, Perl's fork() simply calls it. On some platforms such as Windows where the fork() system call is not available, Perl can be built to emulate fork() at the interpreter level.The fork() function is used to clone a current process. This call create a new process running the same program at the same point. It returns the child pid to the parent process, 0 to the child process, or under if the fork is ... Read More
1 2 3 4 5 ... 16 Next