Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Server Side Programming Articles - Page 2062 of 2650
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
252 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
271 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
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 any other statement is executed.Every END block is executed just before the perl interpreter exits.The BEGIN and END blocks are particularly useful when creating Perl modules.Following example shows its usage −Example Live Demo#!/usr/bin/perl package Foo; print "Begin and Block Demo"; BEGIN { print "This is BEGIN Block" } END { ... Read More
380 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 enable the construction of modules which, when used, won't clobber variables and functions outside of the modules's own namespace.The package stays in effect until either another package statement is invoked, or until the end of the current block or file.You can explicitly refer to variables within a package using the :: package ... Read More
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
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 HTTP header. Web server provides this message to the CGI script in the form of the standard input.Below is the Perl script called hello_post.cgi, to handle input given by the web browser. This script will handle GET as well as POST method.#!/usr/bin/perl local ($buffer, @pairs, $pair, $name, $value, %FORM); # ... Read More
680 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 information into name/value pairs @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%(..)/pack("C", hex($1))/eg; $FORM{$name} = $value; } $first_name = $FORM{first_name}; $last_name = $FORM{last_name}; print "Content-type:text/html\r\r"; print ""; print ""; print "Hello - Second CGI ... Read More
324 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 header will be different from the header mentioned in previous section. For example, if you want to make a FileName file downloadable from a given link then it's syntax will be as follows −#!/usr/bin/perl # HTTP Header print "Content-Type:application/octet-stream; name = \"FileName\"\r"; print "Content-Disposition: attachment; filename = \"FileName\"\r"; # Actual ... Read More
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 length of the query information. It's available only for POST requests3HTTP_COOKIEReturns the set cookies in the form of key & value pair.4HTTP_USER_AGENTThe User-Agent request-header field contains information about the user agent originating the request. Its name of the web browser.5PATH_INFOThe path for the CGI script.6QUERY_STRINGThe URL-encoded information that is sent ... Read More