Mohd Mohtashim has Published 238 Articles

The system() Function in Perl

Mohd Mohtashim

Mohd Mohtashim

Updated on 02-Dec-2019 10:44:06

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 ... Read More

Backstick Operator in Perl

Mohd Mohtashim

Mohd Mohtashim

Updated on 02-Dec-2019 10:38:35

237 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 ... Read More

What are Perl Modules?

Mohd Mohtashim

Mohd Mohtashim

Updated on 02-Dec-2019 10:37:10

252 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 ... Read More

BEGIN and END Blocks in Perl

Mohd Mohtashim

Mohd Mohtashim

Updated on 02-Dec-2019 10:32:20

2K+ Views

You may define any number of code blocks named BEGIN and END in Perl programs, which act as constructors and destructors respectively.BEGIN { ... } END { ... } BEGIN { ... } END { ... }Every BEGIN block is executed after the perl script is loaded and compiled but before ... Read More

What are Packages in Perl?

Mohd Mohtashim

Mohd Mohtashim

Updated on 02-Dec-2019 10:30:06

365 Views

The package statement in Perl switches the current naming context to a specified namespace (symbol table). Thus −A package is a collection of code which lives in its own namespace.A namespace is a named collection of unique variable names (also called a symbol table).Namespaces prevent variable name collisions between packages.Packages ... Read More

How to use Cookies in CGI in Perl?

Mohd Mohtashim

Mohd Mohtashim

Updated on 02-Dec-2019 08:14:12

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 ... Read More

Using POST Methods in Perl

Mohd Mohtashim

Mohd Mohtashim

Updated on 02-Dec-2019 08:11:48

2K+ Views

A more reliable method of passing information to a CGI program is the POST method. This packages the information in exactly the same way as GET methods, but instead of sending it as a text string after a ? in the URL, it sends it as a separate message as a part of ... Read More

Using GET Methods in Perl

Mohd Mohtashim

Mohd Mohtashim

Updated on 02-Dec-2019 08:09:56

666 Views

Here is a simple URL which will pass two values to hello_get.cgi program using GET method.http://www.tutorialspoint.com/cgi-bin/hello_get.cgi?first_name=ZARA&last_name=ALIBelow is hello_get.cgi script to handle input given by web browser.#!/usr/bin/perl local ($buffer, @pairs, $pair, $name, $value, %FORM); # Read in text $ENV{'REQUEST_METHOD'} =~ tr/a-z/A-Z/; if ($ENV{'REQUEST_METHOD'} eq "GET") {    $buffer = $ENV{'QUERY_STRING'}; } # Split ... Read More

Raise a "File Download" Dialog Box using Perl

Mohd Mohtashim

Mohd Mohtashim

Updated on 02-Dec-2019 08:05:20

313 Views

Sometime it is desired that you want to give option where a user will click a link and it will pop up a "File Download" dialogue box to the user instead of displaying actual content. This is very easy and will be achieved through HTTP header using Perl Script.This HTTP ... Read More

Perl CGI Environment Variables

Mohd Mohtashim

Mohd Mohtashim

Updated on 02-Dec-2019 08:04:03

2K+ Views

All the Perl CGI program will have access to the following environment variables. These variables play an important role while writing any CGI program in Perl.Sr.NoVariables Names & Description1CONTENT_TYPEThe data type of the content. Used when the client is sending attached content to the server. For example file upload, etc.2CONTENT_LENGTHThe ... Read More

Advertisements