Set - 1

Question 11 :

How to turn on Perl warnings? Why is that important?

Answer :

Perl is very forgiving of strange and sometimes wrong code, which can mean hours spent searching for bugs and weird results. Turning on warnings helps uncover common mistakes and strange places and save a lot of debugging time in the long run. There are various ways of turning on Perl warnings: 
For Perl one-liner, use -w option on the command line. 
On Unix or Windows, use the -w option in the shebang line (The first # line in the script). Note: Windows Perl interpreter may not require it. 
For other systems, choose compiler warnings, or check compiler documentation.


Question 12 :

What are scalar data and scalar variables?

Answer :

Perl has a flexible concept of data types. Scalar means a single thing, like a number or string. So the Java concept of int, float, double and string equals to Perl\'s scalar in concept and the numbers and strings are exchangeable. Scalar variable is a Perl variable that is used to store scalar data. It uses a dollar sign $ and followed by one or more alphanumeric characters or underscores. It is case sensitive.


Question 13 :

Why should I use the -w argument with my Perl programs?

Answer :

Many Perl developers use the -w option of the interpreter, especially during the development stages of an application. This warning option turns on many warning messages that can help you understand and debug your applications.
To use this option on Unix systems, just include it on the first line of the program, like this:

#!/usr/bin/perl -w

If you develop Perl apps on a DOS/Windows computer, and you're creating a program named myApp.pl, you can turn on the warning messages when you run your program like this:

perl -w myApp.pl

 


Question 14 :

Assuming $_ contains HTML, which of the following substitutions will remove all tags in it?
1.s/<.*>//g;
2.s/<.*?>//gs;
3.s/<\/?[A-Z]\w*(?:\s+[A-Z]\w*(?:\s*=\s*(?:(["']).*?\1|[\w-.]+))?)*\s*>//gsix;

Answer :

You can't do that.
If it weren't for HTML comments, improperly formatted HTML, and tags with interesting data like < SCRIPT >, you could do this. Alas, you cannot. It takes a lot more smarts, and quite frankly, a real parser.


Question 15 :

I want users send data by formmail but when they send nothing or call it from web site they will see error.
codes in PHP like this:

if (isset($HTTP_POST_VARS)){
	..........
}
else{
	echo ("error lalalalal")
}

How it will look in perl?

Answer :

In php it will be like 

if (isset($HTTP_POST_VARS)){
	....
}
//In perl, tried this.
if ($ENV{'REQUEST_METHOD'} eq 'POST'){
	.....
}