AJAX
Perl Interview Questions?
What is use of ‘strict’ in perl ?
The module strict restricts ‘unsafe constructs’, according to the perldocs
When you enable the strict module, the three things that Perl becomes strict about are:
• Variables ‘vars’
• References ‘refs’
• Subroutines ‘subs’
Strict variables are useful. Essentially, this means that all variables must be declared, that is defined before use. Furthermore, each variable must be defined with my or fully qualified
What is scalars in perl ?
The most basic kind of variable in Perl is the scalar variable. Scalar variables hold both strings and numbers, and are remarkable in that strings and numbers are completely interchangable. For example, the statement
$priority = 9;
sets the scalar variable $priority to 9, but you can also assign a string to exactly the same variable:
$priority = ‘high’
Perl difference between lists and arrays ?
A list is a fixed collection of scalars. An array is a variable that holds a variable collection of scalars.
Array operations, which change the scalars, reaaranges them, or adds or subtracts some scalars, only work on arrays. These can’t work on a list, which is fixed. Array operations include shift, unshift, push, pop, and splice.
You can change an array element, but you can’t change a list element.
What is the use of ‘defined’?
defined EXPR
defined
Returns true if EXPR has a value other than the undef value, or checks the value of $_ if EXPR is not specified.
If EXPR is a function or function reference, then it returns true if the function has been defined.
Return Value
• 0 if EXPR contains undef
• 1 if EXPR contains a valid value or reference
#!/usr/bin/perl $var1 = "This is defined"; if( defined($var1) ){ print "$var1\n"; } if( defined($var2) ){ print "var2 is also defined\n"; }else{ print "var2 is not defined\n"; } This will produce following result This is defined var2 is not defined |
What is ajax synchronous and asynchronous?
Synchronous – Script stops and waits for the server to send back a reply before continuing. There are some situations where Synchronous Ajax is mandatory.
In standard Web applications, the interaction between the customer and the server is synchronous. This means that one has to happen after the other. If a customer clicks a link, the request is sent to the server, which then sends the results back.
Because of the danger of a request getting lost and hanging the browser, synchronous javascript isn’t recommended for anything outside of (onbefore)unload event handlers, but if you need to hear back from the server before you can allow the user to navigate away from the page, synchronous Javascript isn’t just your best option.
Synchronous AJAX function Example using GET.
function getFile(url) { if (window.XMLHttpRequest) { AJAX=new XMLHttpRequest(); } else { AJAX=new ActiveXObject("Microsoft.XMLHTTP"); } if (AJAX) { AJAX.open("GET", url, false); AJAX.send(null); return AJAX.responseText; } else { return false; } } var fileFromServer = getFile('http://www.phpmind.com/om.txt'); |
Synchronous AJAX function Example using POST.
function getFile(url, passData) { if (window.XMLHttpRequest) { AJAX=new XMLHttpRequest(); } else { AJAX=new ActiveXObject("Microsoft.XMLHTTP"); } if (AJAX) { AJAX.open("POST", url, false); AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); AJAX.send(passData); return AJAX.responseText; } else { return false; } } var fileFromServer = getFile('http://www.phpmind.com/data.php', sendThisDataAsAPost); |
Asynchronous – Where the script allows the page to continue to be processed and will handle the reply if and when it arrives. If anything goes wrong in the request and/or transfer of the file, your program still has the ability to recognize the problem and recover from it.
Processing asynchronously avoids the delay while the retrieval from the server is taking place because your visitor can continue to interact with the web page and the requested information will be processed with the response updating the page as and when it arrives.
What is Ajax?
Ajax (sometimes called Asynchronous JavaScript and XML) is a way of programming for the Web that gets rid of the hourglass. Data, content, and design are merged together into a seamless whole. When your customer clicks on something on an Ajax driven application, there is very little lag time. The page simply displays what they’re asking for.
Ajax is a way of developing Web applications that combines:
- XHTML and CSS standards based presentation
- Interaction with the page through the DOM
- Data interchange with XML and XSLT
- Asynchronous data retrieval with XMLHttpRequest
- JavaScript to tie it all together
How to send bulk email through email software?
If you’re sending an email campaign to thousands or millions of user using some software then you’re going to need a reliable mail server. Most of the shared servers are not going to allow you send more email. There are a lot of restrictions and host may impose email sending restrictions which makes it impossible to send.
There are ways to send –
1. You can send emails out application your web host’s mail sending engine. This advantage is accomplished if you’re sending only a few hundred emails per month, about as soon as you go over this, your host will not allow you to send more. This option is good for sending email using online php tools so many are available please check with google ![]()
2. You can buy your own committed server from service provider like RackSpace.com or netatlantic.com (we are using this!) and configure it to send emails. We send 60000 emails per month without any issue, they have easy to use web interface. We just create newsletter test and send to our subscribers. It works perfectly.
3. Most effective option is using third party mail server like SMTP.com. Even if you are using shared server you can use there service if you have tones of email to send. Don’t forget to negotiate for discount if you are using there partners software!!
How to delete a folder with PHP?
To delete a file, or a folder and its contents i have compiled a recursive algorithm.
Hope this will be useful for all of you.
<?php function rmdirr($dirname) { // Sanity check if (!file_exists($dirname)) { return false; } // Simple delete for a file if (is_file($dirname) || is_link($dirname)) { return unlink($dirname); } // Loop through the folder $dir = dir($dirname); while (false !== $entry = $dir->read()) { // Skip pointers if ($entry == '.' || $entry == '..') { continue; } // Recurse rmdirr($dirname . DIRECTORY_SEPARATOR . $entry); } // Clean up $dir->close(); return rmdir($dirname); } ?> |
How to get the page name of the current URL?
Using this script you can get PHP current page from a url.
function CPageName() {
return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
}
echo "The current page name is ".CPageName();



