Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 27-01-2011
Member
 
Join Date: Sep 2010
Posts: 13
Program Structure in Perl

I just want to know about the Program Structure in Perl. Let me tell you that I am having some concepts of regular expressions, but that too not much. Regular expressions are one of the best features of Perl that make it very flexible. Given the intensive use made of it in this program, you should take this opportunity to examine them in detail. Regular expressions are defined in theoretical computer science as an expression used to describe sets of strings. The main task that uses a regular expression is matching, ie the verification that a string belongs to the set described by the regular. I am having this much knowledge (basic ), so thought that you guys will help me in resolving my problem. Please tell me about the program structure with some examples, so that it would be better for me to understand. It would be much helpful, if you provide some more information about regular expressions and reading parameters.
Reply With Quote
  #2  
Old 27-01-2011
Member
 
Join Date: Oct 2008
Posts: 101
Re: Program Structure in Perl

Let's analyze the program. The structure of the main routine is very simple, as shown in the following listing:
Code:
$ LOG_FILE = '/ var / log / httpd / access_log';
 $ LogFile = $ LOG_FILE;
 $ Begin = 0;
 $ End = 999999999;
 $ Url = $ = $ Site = $ nURL NSite ='';
 StatUrlCount StatUrlTot% =% = ();
 StatReqCount StatReqTot% =% = ();
 Main & (& GetParam);
 exit (0);
 sub Main {
   & ParseParam (@_);
   &AnalizeLog;
   & PrintexResults;
 }
parameters are read (ParseParam), then we analyze the log files (AnalizeLog), and finally printing the results (PrintexResults). The parameters are stored in global variables: the name of the log file in $ LogFile, dates of start and end of the period to be analyzed in $ $ Begin and End, the URLs and sites to be considered or to exclude $ url, $ nURL, $ site, $ NSite. The results of the statistics are collected using associative arrays StatUrlCount%,% StatUrlTot, StatReqCount%,% StatReqTot.
Reply With Quote
  #3  
Old 27-01-2011
Member
 
Join Date: Apr 2009
Posts: 40
Re: Program Structure in Perl

Let me tell you some more things about the program structure in Perl. Dates are stored in a format that makes it easy comparison, a number of 8 digits where the first four are the year, the next two are the month and finally the last two days. For example, July 9, 1968 corresponds to the figure 19,680,709. Although there is a match to a one-digit dates, however, to date figures are more and more you can compare them and it is straightforward to derive the figure of the date, which is all we need.
Reply With Quote
  #4  
Old 27-01-2011
Member
 
Join Date: Jan 2009
Posts: 124
Re: Program Structure in Perl

Quote:
Regular expressions are one of the best features of Perl that make it very flexible. Given the intensive use made of it in this program, you should take this opportunity to examine them in detail.
In fact, the Perl (and many other programs) use this concept in a broader way than the theoretical definition. First, the matching is applied not only to test the entire string of correspondence, but is normally carried out a search of substrings that satisfy. Of course you can specify that you want an entire matching string and not a substring (and it is often the case). There are also two other variants of regular expressions that cause side effects: these modify the string on which the matching is carried out. Side effects are replacements of strings and translations, ie, substitutions of individual characters and the useful extraction of substrings. To use regular expressions using the = ~ operator, which applies to a matching string and the side effects that cause the expression. The first operand of this operator is a scalar variable, while the second operand is the regular expression itself, which in this general form:
[<prefix>] <delim> <regexp> <delim> [<string> <delim> [<suffix>]]
Reply With Quote
  #5  
Old 27-01-2011
Member
 
Join Date: Apr 2009
Posts: 26
Re: Program Structure in Perl

The operator always returns a value, which can always be interpreted as true if the application of the regular expression is successful, false otherwise. Now let's see some examples:
Code:
(A) / 0 /
	 (B) m / \ s * | \ w + /
	 (C) s / [\ t \ n] + / / g
	 (D) tr / az / AZ /
The <prefix> can be m (matching), s (replacement), tr (translation). The bars / are normally used as delimiters and have a function similar to the quotes used to delimit a string. In fact, you can use any character as a delimiter (it is sufficient that the first and last are the same) but if the fence is not necessary to specify the bar <prefix>. If the <delim> <prefix> and the bar is omitted, it is assumed m. The <suffix> used to specify the options side-effect caused by the regular expression, for example, the repetition of a replacement, such as (c). The <regexp> proper use alphanumeric characters in their literal meaning (eg / a / matches "a"), while non-alphanumeric characters generally have a special meaning, and therefore we call them wildcards. The following table summarizes the main wildcards and their meanings.
Code:
CHARACTERS
 .  any character except newline
 [Az] any character listed 
	 (The - results in a sequence, reversing the class ^)
 \ S whitespace
 \ W a letter or decimal _
 \ D to one decimal place
 \ S as [^ \ s]
 \ W as [^ \ w]
 \ D [^ \ d]
 ITERATIVE
 * 0 or more occurrences
 + 1 or more occurrences
 ?  0 or 1 occurrences
 {N} matches exactly n occurrences
 {N,} at least n occurrences
 {N, m} occurrences of nam
 OTHER
 ^ Start of string
 $ End of string
 | Alternative 
 () Grouping
You can remove the special meaning of a wild card and use it in its literal meaning by preceding it with a backslash, for example / \ * / matches "*". Some alphanumeric characters instead, if they become wildcards are preceded by a backslash and acquire a special meaning that would not normally have, for example / \ d / matches one decimal place.
Reply With Quote
  #6  
Old 27-01-2011
Member
 
Join Date: Jan 2009
Posts: 84
Re: Program Structure in Perl

The subroutine GetParam implements a technique that allows you to specify the parameters from the command line is that the environment variable QUERY_STRING (that contains the specified input from a form when the program is invoked as a CGI). The parameters are supplied on the command line using syntax <key> = <value> intentionally similar (but not identical) to the format provided by a CGI QUERY_STRING. The GetParam deals precisely to fill this gap by standardizing the input provided by the CGI with the input provided by the command line. The main differences between the line of command and QUERY_STRING are the various parameters in the separator, which is the space in the former case while it is a & in the second, plus some characters are encoded in a particular format. In fact, after breaking the QUERY_STRING GetParam the worries about a "clean" input by decoding the encoded characters. The result is an array that has the same form whether it comes from the line of command from QUERY_STRING, ready to be analyzed by ParseParam. Note that you set the variable $ IsCgi, so you can tell where it is used, the behavior of the command-line behavior as CGI. In practice there are only two cases where you have to make this distinction when considering the parameter file (for security reasons is ignored when the program is invoked as a CGI), and when you print the results (invoked as a CGI program must produce output that begins with a string like "Content-type: text / html").
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Program Structure in Perl"
Thread Thread Starter Forum Replies Last Post
What is PERL and what are its uses? Gadin Software Development 10 08-01-2011 07:33 PM
Perl VS Python Trance Maniac Software Development 6 06-10-2010 11:01 PM
Variables and data structure in Perl Monty1 Tips & Tweaks 2 28-09-2010 07:53 PM
Executing a program with exec perl Ash maker Software Development 5 08-03-2010 02:02 PM
Modification of an existing program in Perl AdityaR Software Development 3 26-11-2009 06:02 PM


All times are GMT +5.5. The time now is 06:26 PM.