PERL Articles

Page 8 of 15

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

Mukul Latiyan
Mukul Latiyan
Updated on 26-Dec-2022 5K+ Views

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 Perl array contains a particular value?

Mukul Latiyan
Mukul Latiyan
Updated on 26-Dec-2022 9K+ Views

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
Mukul Latiyan
Updated on 26-Dec-2022 11K+ Views

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
Pradeep Kumar
Updated on 25-Jul-2022 778 Views

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
Mohd Mohtashim
Updated on 02-Dec-2019 743 Views

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
Mohd Mohtashim
Updated on 02-Dec-2019 1K+ Views

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;

Read More

The system() Function in Perl

Mohd Mohtashim
Mohd Mohtashim
Updated on 02-Dec-2019 15K+ Views

You can use system() Perl function to execute any Unix command, whose output will go to the output of the perl script. By default, it is the screen, i.e., STDOUT, but you can redirect it to any file by using redirection operator > −#!/usr/bin/perl system( "ls -l") 1;When above code is executed, it lists down all the files and directories available in the current directory −drwxr-xr-x 3 root root 4096 Sep 14 06:46 9-14 drwxr-xr-x 4 root root 4096 Sep 13 07:54 android -rw-r--r-- 1 root root 574 Sep 17 15:16 index.htm drwxr-xr-x 3 544 401 4096 Jul 6 16:49 MIME-Lite-3.01 ...

Read More

Backstick Operator in Perl

Mohd Mohtashim
Mohd Mohtashim
Updated on 02-Dec-2019 281 Views

This simplest way of executing any Unix command in Perl Program is by using backstick operator. You simply put your command inside the backstick operator, which will result in execution of the command and returns its result which can be stored as follows −#!/usr/bin/perl @files = `ls -l`; foreach $file (@files) {    print $file; } 1;When the above code is executed, it lists down all the files and directories available in the current directory −drwxr-xr-x 3 root root 4096 Sep 14 06:46 9-14 drwxr-xr-x 4 root root 4096 Sep 13 07:54 android -rw-r--r-- 1 root root 574 Sep 17 ...

Read More

What are Perl Modules?

Mohd Mohtashim
Mohd Mohtashim
Updated on 02-Dec-2019 311 Views

A Perl module is a reusable package defined in a library file whose name is the same as the name of the package with a .pm as extension.A Perl module file called Foo.pm might contain statements like this.#!/usr/bin/perl package Foo; sub bar {    print "Hello $_[0]" } sub blat {    print "World $_[0]" } 1;Few important points about Perl modulesThe functions require and use will load a module.Both use the list of search paths in @INC to find the module.Both functions require and use call the eval function to process the code.The 1; at the bottom causes eval to evaluate to TRUE (and thus not ...

Read More

How to use Cookies in CGI in Perl?

Mohd Mohtashim
Mohd Mohtashim
Updated on 02-Dec-2019 2K+ Views

HTTP protocol is a stateless protocol. But for a commercial website it is required to maintain session information among different pages. For example one user registration ends after transactions which spans through many pages. But how to maintain user's session information across all the web pages?In many situations, using cookies is the most efficient method of remembering and tracking preferences, purchases, commissions, and other information required for better visitor experience or site statistics.How It WorksYour server sends some data to the visitor's browser in the form of a cookie. The browser may accept the cookie. If it does, it is ...

Read More
Showing 71–80 of 146 articles
« Prev 1 6 7 8 9 10 15 Next »
Advertisements