<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-2938427049868690639</id><updated>2011-11-27T17:33:03.506-08:00</updated><category term='VB Script'/><category term='Python'/><category term='PHP'/><category term='Perl'/><category term='HTML'/><category term='Scripting Language'/><title type='text'>Scripting Languages</title><subtitle type='html'>Java script, VB Script, shell Shell Script, Perl Script, Python script, TCL faqs</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://scriptingfaqs.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2938427049868690639/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://scriptingfaqs.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Siebel Expert</name><uri>http://www.blogger.com/profile/11533458660230230361</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>13</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2938427049868690639.post-1160729141500005027</id><published>2008-12-12T21:24:00.000-08:00</published><updated>2008-12-23T03:54:08.333-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Scripting Language'/><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><title type='text'>Python Q &amp; A</title><content type='html'>. A program is a set of instructions that a computer follows to perform a task.&lt;br /&gt;. Hardware is all of the physical devices, or components, that a computer is made&lt;br /&gt;of.&lt;br /&gt;. The central processing unit (CPU), main memory, secondary storage devices,&lt;br /&gt;input devices, and output devices.&lt;br /&gt;. The CPU&lt;br /&gt;. Main memory&lt;br /&gt;. Secondary storage&lt;br /&gt;. Input device&lt;br /&gt;. Output device&lt;br /&gt;. The operating system&lt;br /&gt;. A utility program&lt;br /&gt;. Application software&lt;br /&gt;. One byte&lt;br /&gt;. A bit&lt;br /&gt;. The binary numbering system.&lt;br /&gt;. It is an encoding scheme that uses a set of  numeric codes to represent the&lt;br /&gt;English letters, various punctuation marks, and other characters. These numeric&lt;br /&gt;codes are used to store characters in a computer's memory. (ASCII stands for the&lt;br /&gt;American Standard Code for Information Interchange.)&lt;br /&gt;. Unicode&lt;br /&gt;. Digital data is data that is stored in binary, and a digital device is any device that&lt;br /&gt;works with binary data.&lt;br /&gt;. Machine language&lt;br /&gt;. Main memory, or RAM&lt;br /&gt;. The fetch-decode-execute cycle.&lt;br /&gt;. It is an alternative to machine language. Instead of using binary numbers for&lt;br /&gt;instructions, assembly language uses short words that are known as mnemonics.&lt;br /&gt;. A high-level language&lt;br /&gt;. Syntax&lt;br /&gt;. A compiler&lt;br /&gt;. An interpreter&lt;br /&gt;. A syntax error&lt;br /&gt;Chapter&lt;br /&gt;. Any person, group, or organization that is asking you to write a program.&lt;br /&gt;. A single function that the program must perform in order to satisfy the customer.&lt;br /&gt;. A set of well-defined logical steps that must be taken to perform a task.&lt;br /&gt;Gaddis – Starting Out with Python, Appendix D Page&lt;br /&gt;. An informal language that has no syntax rules, and is not meant to be compiled or&lt;br /&gt;executed. Instead, programmers use pseudocode to create models, or "mock-ups"&lt;br /&gt;of programs.&lt;br /&gt;. A diagram that graphically depicts the steps that take place in a program.&lt;br /&gt;. Ovals are terminal symbols. Parallelograms are either output or input symbols.&lt;br /&gt;Rectangles are processing symbols.&lt;br /&gt;. print 'Jimmy Smith'&lt;br /&gt;. print "Python's the best!"&lt;br /&gt;. print 'The cat said "meow"'&lt;br /&gt;. A name that references a value in the computer's memory.&lt;br /&gt;. bottles is illegal because it begins with a number. r&amp;amp;d is illegal because&lt;br /&gt;the &amp;amp; character is not allowed.&lt;br /&gt;. No, it is not because variable names are case-sensitive.&lt;br /&gt;. It is invalid because the variable that is receiving the assignment (in this case&lt;br /&gt;amount) must appear on the left side of the = operator.&lt;br /&gt;. The value is val&lt;br /&gt;. value will reference an int. value will reference a float. value will&lt;br /&gt;reference a float. value will reference an int. value will reference a&lt;br /&gt;str (string).&lt;br /&gt;.&lt;br /&gt;. sales = input('Enter the sales for the week: ')&lt;br /&gt;. last_name = input("Enter the customer's last name: ")&lt;br /&gt;. Complete the following table by writing the value of each expression in the Value&lt;br /&gt;column.&lt;br /&gt;Expression Value&lt;br /&gt;-----------------------------------------------&lt;br /&gt; +  * &lt;br /&gt; /  - &lt;br /&gt; +  *  - &lt;br /&gt;( + ) * &lt;br /&gt; / ( - )&lt;br /&gt; +  * ( - )&lt;br /&gt;float() /  .&lt;br /&gt;float( / ) .&lt;br /&gt;int(. / .)&lt;br /&gt;.&lt;br /&gt;.&lt;br /&gt;Chapter&lt;br /&gt;. A function is a group of statements that exist within a program for the purpose of&lt;br /&gt;performing a specific task.&lt;br /&gt;. A large task is divided into several smaller tasks that are easily performed.&lt;br /&gt;Gaddis – Starting Out with Python, Appendix D Page&lt;br /&gt;. If a specific operation is performed in several places in a program, a function can&lt;br /&gt;be written once to perform that operation, and then be executed any time it is&lt;br /&gt;needed.&lt;br /&gt;. Functions can be written for the common tasks that are needed by the different&lt;br /&gt;programs. Those functions can then be incorporated into each program that needs&lt;br /&gt;them.&lt;br /&gt;. When a program is developed as a set of functions that each performs an&lt;br /&gt;individual task, then different programmers can be assigned the job of writing&lt;br /&gt;different functions.&lt;br /&gt;. A function definition has two parts: a header and a block. The header indicates the&lt;br /&gt;starting point of the function, and the block is a list of statements that belong to&lt;br /&gt;the function.&lt;br /&gt;. To call a function means to execute the function.&lt;br /&gt;. When the end of the function is reached, the computer returns back to the part of&lt;br /&gt;the program that called the function, and the program resume execution at that&lt;br /&gt;point.&lt;br /&gt;. Because the Python interpreter uses the indentation to determine where a block&lt;br /&gt;begins and ends.&lt;br /&gt;.&lt;br /&gt;• The overall task that the program is to perform is broken down into a series of&lt;br /&gt;subtasks.&lt;br /&gt;• Each of the subtasks is examined to determine whether it can be further broken&lt;br /&gt;down into more subtasks. This step is repeated until no more subtasks can be&lt;br /&gt;identified.&lt;br /&gt;• Once all of the subtasks have been identified, they are written in code.&lt;br /&gt;. A local variable is a variable that is declared inside a function. It belongs to the&lt;br /&gt;function in which it is declared, and only statements in the same function can&lt;br /&gt;access it.&lt;br /&gt;. The part of a program in which a variable may be accessed.&lt;br /&gt;. Yes, it is permissible.&lt;br /&gt;. Arguments&lt;br /&gt;. Parameters&lt;br /&gt;. A parameter variable’s scope is usually the entire function in which the parameter&lt;br /&gt;is declared.&lt;br /&gt;. No, it does not.&lt;br /&gt;. The entire program&lt;br /&gt;. Here are three:&lt;br /&gt;• Global variables make debugging difficult. Any statement in a program can&lt;br /&gt;change the value of a global variable. If you find that the wrong value is being&lt;br /&gt;stored in a global variable, you have to track down every statement that&lt;br /&gt;accesses it to determine where the bad value is coming from. In a program&lt;br /&gt;with thousands of lines of code, this can be difficult.&lt;br /&gt;• Functions that use global variables are usually dependent on those variables. If&lt;br /&gt;you want to use such a function in a different program, you will most likely&lt;br /&gt;have to redesign it so it does not rely on the global variable.&lt;br /&gt;Gaddis – Starting Out with Python, Appendix D Page&lt;br /&gt;• Global variables make a program hard to understand. A global variable can be&lt;br /&gt;modified by any statement in the program. If you are to understand any part of&lt;br /&gt;the program that uses a global variable, you have to be aware of all the other&lt;br /&gt;parts of the program that access the global variable.&lt;br /&gt;. A global constant is a name that is available to every function in the program. It is&lt;br /&gt;permissible to use global constants. Because their value cannot be changed during&lt;br /&gt;the program's execution, you do not have to worry about its value being altered.&lt;br /&gt;Chapter&lt;br /&gt;. A logical design that controls the order in which a set of statements execute.&lt;br /&gt;. It is a program structure that can execute a set of statements only under certain&lt;br /&gt;circumstances.&lt;br /&gt;. A decision structure that provides a single alternative path of execution. If the&lt;br /&gt;condition that is being tested is true, the program takes the alternative path.&lt;br /&gt;. An expression that can be evaluated as either true or false.&lt;br /&gt;. You can determine whether one value is greater than, less than, greater than or&lt;br /&gt;equal to, less than or equal to, equal to, or not equal to another value.&lt;br /&gt;.&lt;br /&gt;if y == :&lt;br /&gt;x =&lt;br /&gt;.&lt;br /&gt;if sales &gt;= :&lt;br /&gt;commission = .&lt;br /&gt;. A dual alternative decision structure has two possible paths of execution—one path&lt;br /&gt;is taken if a condition is true, and the other path is taken if the condition is false.&lt;br /&gt;. if-else&lt;br /&gt;. When the condition is false&lt;br /&gt;. z is not less than a.&lt;br /&gt;. Boston&lt;br /&gt;New York&lt;br /&gt;.&lt;br /&gt;if number == :&lt;br /&gt;print 'One'&lt;br /&gt;elsif number == :&lt;br /&gt;print 'Two'&lt;br /&gt;elsif number == :&lt;br /&gt;print 'Three'&lt;br /&gt;else:&lt;br /&gt;print 'Unknown'&lt;br /&gt;. It is an expression that is created by using a logical operator to combine two&lt;br /&gt;Boolean subexpressions.&lt;br /&gt;.&lt;br /&gt;F&lt;br /&gt;Gaddis – Starting Out with Python, Appendix D Page&lt;br /&gt;T&lt;br /&gt;F&lt;br /&gt;F&lt;br /&gt;T&lt;br /&gt;T&lt;br /&gt;T&lt;br /&gt;F&lt;br /&gt;F&lt;br /&gt;T&lt;br /&gt;.&lt;br /&gt;T&lt;br /&gt;F&lt;br /&gt;T&lt;br /&gt;T&lt;br /&gt;. The and operator: If the expression on the left side of the and operator is false,&lt;br /&gt;the expression on the right side will not be checked.&lt;br /&gt;The or operator: If the expression on the left side of the or operator is true, the&lt;br /&gt;expression on the right side will not be checked.&lt;br /&gt;.&lt;br /&gt;if speed &gt;=  and speed &lt;= :&lt;br /&gt;print 'The number is valid'&lt;br /&gt;.&lt;br /&gt;if speed &lt;&gt; :&lt;br /&gt;print 'The number is not valid'&lt;br /&gt;. True or False&lt;br /&gt;. A variable that signals when some condition exists in the program.&lt;br /&gt;Chapter&lt;br /&gt;. A structure that causes a section of code to repeat.&lt;br /&gt;. A loop that uses a true/false condition to control the number of times that it&lt;br /&gt;repeats.&lt;br /&gt;. A loop that repeats a specific number of times.&lt;br /&gt;. An execution of the statements in the body of the loop.&lt;br /&gt;. Before&lt;br /&gt;. None. The condition count &lt;  will be false to begin with.&lt;br /&gt;. A loop that has no way of stopping, and repeats until the program is interrupted.&lt;br /&gt;.&lt;br /&gt;for x in range():&lt;br /&gt;print 'I love to program!'&lt;br /&gt;.&lt;br /&gt;&lt;br /&gt;Gaddis – Starting Out with Python, Appendix D Page&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;. A variable that is used to accumulate the total of a series of numbers.&lt;br /&gt;. Yes, it should be initialized with the value . This is because values are added to&lt;br /&gt;the accumulator by a loop. If the accumulator does not start at the value , it will&lt;br /&gt;not contain the correct total of the numbers that were added to it when the loop&lt;br /&gt;ends.&lt;br /&gt;.&lt;br /&gt;.&lt;br /&gt;&lt;br /&gt;. a) quantity +=&lt;br /&gt;b) days_left -=&lt;br /&gt;c) price *=&lt;br /&gt;d) price /=&lt;br /&gt;. A sentinel is a special value that marks the end of a list of items.&lt;br /&gt;. A sentinel value must be unique enough that it will not be mistaken as a regular&lt;br /&gt;value in the list.&lt;br /&gt;. It means that if bad data (garbage) is provided as input to a program, the program&lt;br /&gt;will produce bad data (garbage) as output.&lt;br /&gt;. When input is given to a program, it should be inspected before it is processed. If&lt;br /&gt;the input is invalid, then it should be discarded and the user should be prompted to&lt;br /&gt;enter the correct data.&lt;br /&gt;. The input is read, and then a pretest loop is executed. If the input data is invalid,&lt;br /&gt;the body of the loop executes. In the body of the loop, an error message is&lt;br /&gt;Gaddis – Starting Out with Python, Appendix D Page&lt;br /&gt;displayed so the user will know that the input was invalid, and then the input read&lt;br /&gt;again. The loop repeats as long as the input is invalid.&lt;br /&gt;. It is the input operation that takes place just before an input validation loop. The&lt;br /&gt;purpose of the priming read is to get the first input value.&lt;br /&gt;. None.&lt;br /&gt;Chapter&lt;br /&gt;. The difference is that a value returning function returns a value back to the&lt;br /&gt;statement that called it. A simple function does not return a value.&lt;br /&gt;. A prewritten function that performs some commonly needed task.&lt;br /&gt;. The term “black box” is used to describe any mechanism that accepts input,&lt;br /&gt;performs some operation (that cannot be seen) using the input, and produces&lt;br /&gt;output.&lt;br /&gt;. It assigns a random integer in the range of  through  to the variable x.&lt;br /&gt;. It prints a random integer in the range of  through .&lt;br /&gt;. It prints a random integer in the range of  through .&lt;br /&gt;print random.randrange(, )&lt;br /&gt;. It prints a random floating point number in the range of . up to, but not&lt;br /&gt;including, ..&lt;br /&gt;. It prints a random floating-point number in the range of . through ..&lt;br /&gt;. What is the purpose of the return statement in a function?&lt;br /&gt;. Look at the following function definition:&lt;br /&gt;def do_something(number):&lt;br /&gt;return number *&lt;br /&gt;a. do_something&lt;br /&gt;b. It returns a value that is twice the argument passed to it.&lt;br /&gt;c.&lt;br /&gt;. A function that returns either True or False.&lt;br /&gt;. import math&lt;br /&gt;. square_root = math.sqrt()&lt;br /&gt;. angle = math.radians()&lt;br /&gt;Chapter&lt;br /&gt;. A file that a program writes data to. It is called an output file because the program&lt;br /&gt;sends output to it.&lt;br /&gt;. A file that a program reads data from. It is called an input file because the&lt;br /&gt;program receives input from it.&lt;br /&gt;. () Open the file () Process the file () Close the file&lt;br /&gt;. Text and binary. A text file contains data that has been encoded as text, using a&lt;br /&gt;scheme such as ASCII. Even if the file contains numbers, those numbers are&lt;br /&gt;stored in the file as a series of characters. As a result, the file may be opened and&lt;br /&gt;viewed in a text editor such as Notepad. A binary file contains data that has not&lt;br /&gt;Gaddis – Starting Out with Python, Appendix D Page&lt;br /&gt;been converted to text. As a consequence, you cannot view the contents of a&lt;br /&gt;binary file with a text editor.&lt;br /&gt;. Sequential and direct access. When you work with a sequential access file, you&lt;br /&gt;access data from the beginning of the file to the end of the file. When you work&lt;br /&gt;with a direct access file, you can jump directly to any piece of data in the file&lt;br /&gt;without reading the data that comes before it.&lt;br /&gt;. The file's name on the disk, and the name of a variable that references a file&lt;br /&gt;object.&lt;br /&gt;. The file's contents are erased.&lt;br /&gt;. Opening a file creates a connection between the file and the program. It also&lt;br /&gt;creates an association between the file and a file object.&lt;br /&gt;. Closing a file disconnects the program from the file.&lt;br /&gt;. A file’s read position marks the location of the next item that will be read from&lt;br /&gt;the file. When an input file is opened, its read position is initially set to the first&lt;br /&gt;item in the file.&lt;br /&gt;. You open the file in append mode. When you write data to a file in append mode,&lt;br /&gt;the data is written to the end of the file's existing contents.&lt;br /&gt;.&lt;br /&gt;outfile = open('numbers.txt', 'w')&lt;br /&gt;for num in range(, ):&lt;br /&gt;outfile.write(str(num) + '\n')&lt;br /&gt;outfile.close()&lt;br /&gt;. The readline method returns an empty string ('') when it has attempted to&lt;br /&gt;read beyond the end of a file.&lt;br /&gt;.&lt;br /&gt;infile = open('numbers.txt', 'r')&lt;br /&gt;line = infile.readline()&lt;br /&gt;while line != '':&lt;br /&gt;print line&lt;br /&gt;line = infile.readline()&lt;br /&gt;infile.close()&lt;br /&gt;. Revise the program that you wrote for Checkpoint .x so to use the for loop&lt;br /&gt;instead of the while loop.&lt;br /&gt;infile = open('data.txt', 'r')&lt;br /&gt;for line in infile:&lt;br /&gt;print line&lt;br /&gt;infile.close()&lt;br /&gt;. A record is a complete set of data that describes one item, and a field is a single&lt;br /&gt;piece of data within a record.&lt;br /&gt;. You copy all of the original file's records to the temporary file, but when you get&lt;br /&gt;to the record that is to be modified, you do not write its old contents to the&lt;br /&gt;temporary file. Instead, you write its new, modified values to the temporary file.&lt;br /&gt;Gaddis – Starting Out with Python, Appendix D Page&lt;br /&gt;Then, you finish copying any remaining records from the original file to the&lt;br /&gt;temporary file.&lt;br /&gt;. You copy all of the original file's records to the temporary file, except for the&lt;br /&gt;record that is to be deleted. The temporary file then takes the place of the original&lt;br /&gt;file. You delete the original file and rename the temporary file, giving it the name&lt;br /&gt;that the original file had on the computer's disk.&lt;br /&gt;. An exception is an error that occurs while a program is running. In most cases, an&lt;br /&gt;exception causes a program to abruptly halt.&lt;br /&gt;. The program halts.&lt;br /&gt;. IOError&lt;br /&gt;. ValueError&lt;br /&gt;Chapter&lt;br /&gt;.&lt;br /&gt;for letter in name:&lt;br /&gt;print letter&lt;br /&gt;.&lt;br /&gt;.&lt;br /&gt;. An IndexError exception will occur if you try to use an index that is out of&lt;br /&gt;range for a particular string.&lt;br /&gt;. Use the built-in len function.&lt;br /&gt;. The second statement attempts to assign a value to an individual character in the&lt;br /&gt;string. Strings are immutable, however, so the expression animal[] cannot&lt;br /&gt;appear on the left side of an assignment operator.&lt;br /&gt;. cde&lt;br /&gt;. defg&lt;br /&gt;. abc&lt;br /&gt;. abcdefg&lt;br /&gt;.&lt;br /&gt;if 'd' in mystring:&lt;br /&gt;print 'yep. tis there.'&lt;br /&gt;. little = big.upper()&lt;br /&gt;.&lt;br /&gt;if ch.isdigit():&lt;br /&gt;print 'Digit'&lt;br /&gt;else:&lt;br /&gt;print 'No digit'&lt;br /&gt;. a A&lt;br /&gt;.&lt;br /&gt;again = raw_input('Do you want to repeat ' + \&lt;br /&gt;'the program or quit? (R/Q) ')&lt;br /&gt;while again.upper() != 'R' and again.upper() != 'Q':&lt;br /&gt;again = raw_input('Do you want to repeat the ' +&lt;br /&gt;'program or quit? (R/Q) ')&lt;br /&gt;Gaddis – Starting Out with Python, Appendix D Page&lt;br /&gt;. $&lt;br /&gt;.&lt;br /&gt;for letter in mystring:&lt;br /&gt;if letter.isupper():&lt;br /&gt;count +=&lt;br /&gt;. [, , , , ]&lt;br /&gt;. [, ]&lt;br /&gt;. Use the built-in len function.&lt;br /&gt;. The remove method removes a specific item from a list. The del statement&lt;br /&gt;removes an item that is at a specific index.&lt;br /&gt;. Use the built-in min and max functions.&lt;br /&gt;. b&lt;br /&gt;.&lt;br /&gt;a) You pass an argument to the index method and it returns the index of&lt;br /&gt;the first element in the list containing that item. If the item is not found in&lt;br /&gt;the list, the method raises a ValueError exception.&lt;br /&gt;b) The insert method allows you to insert an item into a list at a specific&lt;br /&gt;position. You pass two arguments to the insert method: an index&lt;br /&gt;specifying where the item should be inserted and the item that you want&lt;br /&gt;to insert.&lt;br /&gt;c) The sort method rearranges the elements of a list so they appear in&lt;br /&gt;ascending order (from the lowest value to the highest value).&lt;br /&gt;d) The reverse method reverses the order of the items in the list.&lt;br /&gt;. mylist = days.split()&lt;br /&gt;. You use a loop with an accumulator variable. The loop steps through the list,&lt;br /&gt;adding the value of each element to the accumulator.&lt;br /&gt;. You calculate the total of the list elements, then divide the total by the number of&lt;br /&gt;elements in the list.&lt;br /&gt;Chapter&lt;br /&gt;. An object is a software entity that contains both data and procedures.&lt;br /&gt;. Encapsulation is the combining of data and code into a single object.&lt;br /&gt;. When an object’s internal data is hidden from outside code and access to that data&lt;br /&gt;is restricted to the object’s methods, the data is protected from accidental&lt;br /&gt;corruption. In addition, the programming code outside the object does not need to&lt;br /&gt;know about the format or internal structure of the object’s data.&lt;br /&gt;. Public methods can be accessed by entities outside the object. Private methods&lt;br /&gt;cannot be accessed by entities outside the object. They are designed to be&lt;br /&gt;accessed internally.&lt;br /&gt;. The metaphor of a blueprint represents a class.&lt;br /&gt;. Objects are the cookies.&lt;br /&gt;Gaddis – Starting Out with Python, Appendix D Page&lt;br /&gt;. Its purpose is to initialize an object's data attributes. It executes immediately after&lt;br /&gt;the object is created.&lt;br /&gt;. When a method executes, it must have a way of knowing which object's data&lt;br /&gt;attributes it is supposed to operate on. That's where the self parameter comes in.&lt;br /&gt;When a method is called, Python automatically makes its self parameter&lt;br /&gt;reference the specific object that the method is supposed to operate on.&lt;br /&gt;. By starting the attribute's name with two underscores.&lt;br /&gt;. It returns a string representation of the object.&lt;br /&gt;. By passing the object to the built-in str method.&lt;br /&gt;. An attribute that belongs to a specific instance of a class.&lt;br /&gt;.&lt;br /&gt;. A method that returns a value from a class’s attribute but does not change it is&lt;br /&gt;known as an accessor method. A method that stores a value in a data attribute or&lt;br /&gt;changes the value of a data attribute in some other way is known as a mutator&lt;br /&gt;method.&lt;br /&gt;. The top section is where you write the name of the class. The middle section&lt;br /&gt;holds a list of the class’s fields. The bottom section holds a list of the class’s&lt;br /&gt;methods.&lt;br /&gt;. A written description of the real-world objects, parties, and major events related&lt;br /&gt;to the problem.&lt;br /&gt;. If you adequately understand the nature of the problem you are trying to solve,&lt;br /&gt;you can write a description of the problem domain yourself. If you do not&lt;br /&gt;thoroughly understand the nature of the problem, you should have an expert write&lt;br /&gt;the description for you.&lt;br /&gt;. First, identify the nouns, pronouns, and pronoun phrases in the problem domain&lt;br /&gt;description. Then, refine the list to eliminate duplicates, items that you do not&lt;br /&gt;need to be concerned with in the problem, items that represent objects instead of&lt;br /&gt;classes, and items that represent simple values that can be stored in variables.&lt;br /&gt;. The things that the class is responsible for knowing, and the actions that the class&lt;br /&gt;is responsible for doing.&lt;br /&gt;. In the context of this problem, what must the class know? What must the class&lt;br /&gt;do?&lt;br /&gt;. No, not always.&lt;br /&gt;Chapter&lt;br /&gt;. A superclass is a general class and a subclass is a specialized class.&lt;br /&gt;. When one object is a specialized version of another object, there is an “is a”&lt;br /&gt;relationship between them. The specialized object "is a" version of the general&lt;br /&gt;object.&lt;br /&gt;. It inherits all of the superclass's attributes.&lt;br /&gt;. Bird is the superclass and Canary is the subclass.&lt;br /&gt;. I'm a vegetable.&lt;br /&gt;I'm a potato.&lt;br /&gt;Chapter&lt;br /&gt;Gaddis – Starting Out with Python, Appendix D Page&lt;br /&gt;. A recursive algorithm requires multiple method calls. Each method call requires&lt;br /&gt;several actions to be performed by the JVM. These actions include allocating&lt;br /&gt;memory for parameters and local variables, and storing the address of the&lt;br /&gt;program location where control returns after the method terminates. All of these&lt;br /&gt;actions are known as overhead. In an iterative algorithm, which uses a loop, such&lt;br /&gt;overhead is unnecessary.&lt;br /&gt;. A case in which the problem can be solved without recursion.&lt;br /&gt;. Cases in which the problem is solved using recursion.&lt;br /&gt;. When it reaches the base case.&lt;br /&gt;. In direct recursion, a recursive method calls itself. In indirect recursion, method A&lt;br /&gt;calls method B, which in turn calls method A.&lt;br /&gt;Chapter&lt;br /&gt;. The part of a computer and its operating system that the user interacts with.&lt;br /&gt;. A command line interface typically displays a prompt, and the user types a&lt;br /&gt;command which is then executed.&lt;br /&gt;. The program.&lt;br /&gt;. A program that responds to events that take place, such as the user clicking a&lt;br /&gt;button.&lt;br /&gt;. a) Label -- An area that displays one line of text or an image.&lt;br /&gt;b) Entry -- An area in which the user may type a single line of input from&lt;br /&gt;the keyboard.&lt;br /&gt;c) Button -- A button that can cause an action to occur when it is clicked.&lt;br /&gt;d) Frame -- A container that can hold other widgets.&lt;br /&gt;. You create an instance of the Tkinter module's Tk class.&lt;br /&gt;. This function runs like an infinite loop until you close the main window.&lt;br /&gt;. The pack method arranges a widget in its proper position, and it makes the&lt;br /&gt;widget visible when the main window is displayed.&lt;br /&gt;. One will be stacked on top of the other.&lt;br /&gt;. side='left'&lt;br /&gt;. You use an Entry widget's get method to retrieve the data that the user has&lt;br /&gt;typed into the widget.&lt;br /&gt;. It is a string.&lt;br /&gt;. TKinter&lt;br /&gt;. Any value that is stored in the StringVar object will automatically be&lt;br /&gt;displayed in the Label widget.&lt;br /&gt;. You would use radio buttons.&lt;br /&gt;. You would use check buttons.&lt;br /&gt;. When you create a group of Radiobuttons, you associate them all with the&lt;br /&gt;same IntVar object. You also assign a unique integer value to each&lt;br /&gt;Radiobutton widget. When one of the Radiobutton widgets is selected, it&lt;br /&gt;stores its unique integer value in the IntVar object.&lt;br /&gt;Gaddis – Starting Out with Python, Appendix D Page&lt;br /&gt;. You associate a different IntVar object with each Checkbutton. When a&lt;br /&gt;Checkbutton is selected, its associated IntVar object will hold the value .&lt;br /&gt;When a Checkbutton is deselected, its associated IntVar object will hold the&lt;br /&gt;value .&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2938427049868690639-1160729141500005027?l=scriptingfaqs.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://scriptingfaqs.blogspot.com/feeds/1160729141500005027/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2938427049868690639&amp;postID=1160729141500005027' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2938427049868690639/posts/default/1160729141500005027'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2938427049868690639/posts/default/1160729141500005027'/><link rel='alternate' type='text/html' href='http://scriptingfaqs.blogspot.com/2008/12/python-q.html' title='Python Q &amp; A'/><author><name>Siebel Expert</name><uri>http://www.blogger.com/profile/11533458660230230361</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2938427049868690639.post-8230883861933133449</id><published>2008-08-01T03:02:00.000-07:00</published><updated>2008-12-23T03:54:08.333-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='VB Script'/><category scheme='http://www.blogger.com/atom/ns#' term='Scripting Language'/><title type='text'>VBScript Programming Concepts</title><content type='html'>Branching&lt;br /&gt;Allows you to avoid running certain sections of your code&lt;br /&gt;Code is only executed when a condition (or conditions) evaluate to True&lt;br /&gt;Provides a single application the ability to react differently to different input values&lt;br /&gt;&lt;br /&gt;Conditional Statements&lt;br /&gt;“If” statement&lt;br /&gt;Single-statement "If"&lt;br /&gt;Multi-statement "If“&lt;br /&gt;"If ... Else" Statement&lt;br /&gt;"If ... ElseIf" Statement&lt;br /&gt;"Select Case" Statements&lt;br /&gt;If&lt;br /&gt;Performs an operation only if the condition evaluates to True&lt;br /&gt;Used when an action is either performed or not performed.&lt;br /&gt;Syntax:&lt;br /&gt;If…Else&lt;br /&gt;Performs the If portion only if the condition evaluates to True and the Else portion otherwise.&lt;br /&gt;Used in an either or scenario when an operation is always performed.&lt;br /&gt;Syntax:&lt;br /&gt;&lt;br /&gt;If…ElseIf&lt;br /&gt;Only one section can be executed even if many conditions evaluate to True.&lt;br /&gt;Used in a multiple choice scenario&lt;br /&gt;Inclusion of the last Else is optional&lt;br /&gt;Syntax:&lt;br /&gt;Select&lt;br /&gt;Used to choose between 1 of several discrete values for a variable.&lt;br /&gt;Inclusion of Case Else is optional&lt;br /&gt;Less powerful compared to the If statement&lt;br /&gt;Syntax:&lt;br /&gt;Loops&lt;br /&gt;Loops&lt;br /&gt;Allows you to repeat running certain sections of your code&lt;br /&gt;Code executes when a condition (or conditions) evaluate to True&lt;br /&gt;Be careful with Loops. They can result in infinite processing.&lt;br /&gt;Forms&lt;br /&gt;Entry Condition&lt;br /&gt;Entry only when a initial condition is met&lt;br /&gt;Iterated&lt;br /&gt;Repeats for a specific number of times&lt;br /&gt;VBScript Loop Statements&lt;br /&gt;"For ... Next" Statements&lt;br /&gt;"While" Statements&lt;br /&gt;"Do ... Loop" Statements&lt;br /&gt;For Loop&lt;br /&gt;Iterated Loop&lt;br /&gt;Favored because all the loop details are in the definition statement&lt;br /&gt;Syntax:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;While&lt;br /&gt;Entry Condition Loop&lt;br /&gt;Simplest form of the loop&lt;br /&gt;Requires manual modification of the loop condition&lt;br /&gt;Syntax:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Do ... Loop&lt;br /&gt;Similar to the while loop.&lt;br /&gt;Syntax:&lt;br /&gt;&lt;br /&gt;Arrays&lt;br /&gt;Arrays - Introduction&lt;br /&gt;Collection of data elements of the same data type.&lt;br /&gt;Each element in an array is associated with a unique index number.&lt;br /&gt;A specific element in an array can be referred by the index number.&lt;br /&gt;A number of built-in functions are provided to work with arrays. &lt;br /&gt;&lt;br /&gt;Syntax:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Assigning Values to Array Elements&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Retrieving Values from Array Elements &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Array - Types&lt;br /&gt;Two Types&lt;br /&gt;Fixed-size array&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Dynamic array&lt;br /&gt;Array – Fixed Size&lt;br /&gt;Example:&lt;br /&gt;         Dim A(10)&lt;br /&gt;All arrays are zero-based.&lt;br /&gt;Assignment:&lt;br /&gt;    A(0) = 3 …. A(9) = 6&lt;br /&gt;Array - Dynamic array&lt;br /&gt;Use Dim statement to initialize the array without the size or the number of dimensions.&lt;br /&gt;Example&lt;br /&gt;        Dim MyArray()&lt;br /&gt;Subsequently use ReDim to determine the number of dimensions and the size of each dimension.&lt;br /&gt;Example&lt;br /&gt;        ReDim MyArray(25)&lt;br /&gt;&lt;br /&gt;Use Preserve keyword to preserve the contents of the array.&lt;br /&gt;Example&lt;br /&gt;        ReDim Preserve MyArray(30)&lt;br /&gt;Use Erase keyword to release the memory.&lt;br /&gt;Note:&lt;br /&gt;There is no limit to the number of times you can resize. But making an array smaller than it was may lose the data in the eliminated elements.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2938427049868690639-8230883861933133449?l=scriptingfaqs.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://scriptingfaqs.blogspot.com/feeds/8230883861933133449/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2938427049868690639&amp;postID=8230883861933133449' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2938427049868690639/posts/default/8230883861933133449'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2938427049868690639/posts/default/8230883861933133449'/><link rel='alternate' type='text/html' href='http://scriptingfaqs.blogspot.com/2008/08/vbscript-programming-concepts.html' title='VBScript Programming Concepts'/><author><name>Siebel Expert</name><uri>http://www.blogger.com/profile/11533458660230230361</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2938427049868690639.post-4809890140031209586</id><published>2008-08-01T03:00:00.000-07:00</published><updated>2008-12-23T03:54:08.333-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='VB Script'/><category scheme='http://www.blogger.com/atom/ns#' term='Scripting Language'/><title type='text'>VBScript Functions and Procedures</title><content type='html'>VBScript Procedures&lt;br /&gt;There are two kinds of procedures&lt;br /&gt;Sub procedure&lt;br /&gt;&lt;br /&gt;Function procedure&lt;br /&gt;Sub procedures&lt;br /&gt;It is enclosed by Sub and End Sub statements.&lt;br /&gt;Performs actions but don't return a value.&lt;br /&gt;Can take arguments, if no, include an empty set of parentheses ()&lt;br /&gt;Syntax:&lt;br /&gt;Calling the Procedure&lt;br /&gt;It can be called from&lt;br /&gt;Another procedure&lt;br /&gt;Function&lt;br /&gt;Control's event in the body section of an HTML file.&lt;br /&gt;Syntax:&lt;br /&gt;        DisplayMessage&lt;br /&gt;&lt;br /&gt;Passing an Argument&lt;br /&gt;Procedure will take values from outside.&lt;br /&gt;These values are called as “Arguments”.&lt;br /&gt;The number and types of arguments of a procedure depends on various factors.&lt;br /&gt; Example:&lt;br /&gt;&lt;br /&gt;Function&lt;br /&gt;Function procedures&lt;br /&gt;Enclosed by the Function and End Function statements.&lt;br /&gt;Similar to a Sub procedure, but can also return a value.&lt;br /&gt;Can take arguments, if no, include an empty set of parentheses ().&lt;br /&gt;Return a value by assigning a value to its name in one or more statements of the procedure.&lt;br /&gt;The return type of a Function is always a Variant.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2938427049868690639-4809890140031209586?l=scriptingfaqs.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://scriptingfaqs.blogspot.com/feeds/4809890140031209586/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2938427049868690639&amp;postID=4809890140031209586' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2938427049868690639/posts/default/4809890140031209586'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2938427049868690639/posts/default/4809890140031209586'/><link rel='alternate' type='text/html' href='http://scriptingfaqs.blogspot.com/2008/08/vbscript-functions-and-procedures.html' title='VBScript Functions and Procedures'/><author><name>Siebel Expert</name><uri>http://www.blogger.com/profile/11533458660230230361</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2938427049868690639.post-1616356068922391777</id><published>2008-08-01T02:59:00.001-07:00</published><updated>2008-12-23T03:54:08.333-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='VB Script'/><category scheme='http://www.blogger.com/atom/ns#' term='Scripting Language'/><title type='text'>What is a VBScript</title><content type='html'>It is based on the Visual Basic&lt;br /&gt;Supports object oriented features&lt;br /&gt;It is Interpreted by the browser&lt;br /&gt;Loosely Typed&lt;br /&gt;It is used to create the dynamic and interactive website&lt;br /&gt;In ASP (Active Server Pages) VBScript is used as a server side script language.&lt;br /&gt;Adding VBScript Code to an HTML Page&lt;br /&gt;The SCRIPT element is used to add VBScript code to an HTML page.&lt;br /&gt;Syntax:&lt;br /&gt;VBScript – Language Fundamentals&lt;br /&gt;Syntax Rules&lt;br /&gt;VBScript is not case sensitive (except for Strings)&lt;br /&gt;Each statement can only exist on one line&lt;br /&gt;Statements can be either simple statements or compound statements&lt;br /&gt;Comments&lt;br /&gt;Syntax&lt;br /&gt;        ‘ (Single quote) – Comment Symbol&lt;br /&gt;Can be a complete line or a portion of a line.&lt;br /&gt;VBScript does not support multi-line comments. The comment symbol must be put at the start of each comment.&lt;br /&gt;Naming Rules&lt;br /&gt;Must begin with a letter or the underscore &lt;br /&gt;valid: count, strInfo, _data&lt;br /&gt;Invalid: 2day, 4get, *count violate this rule.&lt;br /&gt;Cannot contain special characters except the underscore&lt;br /&gt;valid: Names using alphabets, numbers and the underscore.&lt;br /&gt;Invalid: Names using symbols and other special characters.&lt;br /&gt;Naming Rules&lt;br /&gt;Cannot match a reserved word&lt;br /&gt;Example: for, if, Select&lt;br /&gt;Must be unique within a context&lt;br /&gt;Must be less than 256 characters&lt;br /&gt;VBScript  Variables and Data Types&lt;br /&gt;Variables&lt;br /&gt;Variables hold values that can change during program execution&lt;br /&gt;They function just like temporary storage locations&lt;br /&gt;Declaration of variables is optional, but recommended&lt;br /&gt;The Option Explicit statement is available to require explicit declaration of all variables.&lt;br /&gt;&lt;br /&gt;Dim, Public and Private Statements are used to explicitly declare the variables.&lt;br /&gt;Syntax:&lt;br /&gt;    Dim variableName&lt;br /&gt;Assigning the Value to the Variable&lt;br /&gt;       &lt;variablename&gt; = &lt;value&gt;&lt;br /&gt;Example:&lt;br /&gt;   Dim stud_name – Variable Declaration&lt;br /&gt;   stud_name = “Sanjay” – Assigning the value&lt;br /&gt;Constants&lt;br /&gt;Constant names hold values that cannot change during program execution&lt;br /&gt;Constants should be used in place of hard-coded values&lt;br /&gt;Syntax:&lt;br /&gt;    Const constantName = value&lt;br /&gt;VBScript Data Types&lt;br /&gt;VBScript has only one data type called a Variant which contains either numeric or string information.&lt;br /&gt; VBScript interprets a variant in a manner that is suitable to the type of data it contains.&lt;br /&gt;The different categories of information that can be contained in a Variant are called subtypes.&lt;br /&gt;&lt;br /&gt;VBScript Operators &lt;br /&gt;Type of Operators&lt;br /&gt;Arithmetic Operators&lt;br /&gt;Comparison Operators&lt;br /&gt;Logical Operators&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Arithmetic Operator&lt;br /&gt;Used to perform calculations&lt;br /&gt;Both operands must be numeric values&lt;br /&gt;The result is a numeric value&lt;br /&gt;Comparison&lt;br /&gt;Used to compare the value of two items&lt;br /&gt;Both operands must be of the same data type&lt;br /&gt;The result is a Boolean value&lt;br /&gt;Logical Operator&lt;br /&gt;Used to reduce Boolean values into a single Boolean value&lt;br /&gt;Both operands must be Boolean values&lt;br /&gt;The result is a Boolean value&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2938427049868690639-1616356068922391777?l=scriptingfaqs.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://scriptingfaqs.blogspot.com/feeds/1616356068922391777/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2938427049868690639&amp;postID=1616356068922391777' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2938427049868690639/posts/default/1616356068922391777'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2938427049868690639/posts/default/1616356068922391777'/><link rel='alternate' type='text/html' href='http://scriptingfaqs.blogspot.com/2008/08/what-is-vbscript.html' title='What is a VBScript'/><author><name>Siebel Expert</name><uri>http://www.blogger.com/profile/11533458660230230361</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2938427049868690639.post-5194491038000155072</id><published>2008-07-31T01:57:00.000-07:00</published><updated>2008-12-23T03:54:08.333-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Scripting Language'/><title type='text'>Script for replacing string in file </title><content type='html'>&lt;meta equiv="Content-Type" content="text/html; charset=utf-8"&gt;&lt;meta name="ProgId" content="Word.Document"&gt;&lt;meta name="Generator" content="Microsoft Word 11"&gt;&lt;meta name="Originator" content="Microsoft Word 11"&gt;&lt;link rel="File-List" href="file:///D:%5CDOCUME%7E1%5Cshesu04%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C02%5Cclip_filelist.xml"&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;  &lt;o:documentproperties&gt;   &lt;o:author&gt;support&lt;/o:Author&gt;   &lt;o:version&gt;11.9999&lt;/o:Version&gt;  &lt;/o:DocumentProperties&gt; &lt;/xml&gt;&lt;![endif]--&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;  &lt;w:worddocument&gt;   &lt;w:view&gt;Normal&lt;/w:View&gt;   &lt;w:zoom&gt;0&lt;/w:Zoom&gt;   &lt;w:punctuationkerning/&gt;   &lt;w:validateagainstschemas/&gt;   &lt;w:saveifxmlinvalid&gt;false&lt;/w:SaveIfXMLInvalid&gt;   &lt;w:ignoremixedcontent&gt;false&lt;/w:IgnoreMixedContent&gt;   &lt;w:alwaysshowplaceholdertext&gt;false&lt;/w:AlwaysShowPlaceholderText&gt;   &lt;w:compatibility&gt;    &lt;w:breakwrappedtables/&gt;    &lt;w:snaptogridincell/&gt;    &lt;w:wraptextwithpunct/&gt;    &lt;w:useasianbreakrules/&gt;    &lt;w:dontgrowautofit/&gt;    &lt;w:usefelayout/&gt;   &lt;/w:Compatibility&gt;   &lt;w:browserlevel&gt;MicrosoftInternetExplorer4&lt;/w:BrowserLevel&gt;  &lt;/w:WordDocument&gt; &lt;/xml&gt;&lt;![endif]--&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;  &lt;w:latentstyles deflockedstate="false" latentstylecount="156"&gt;  &lt;/w:LatentStyles&gt; &lt;/xml&gt;&lt;![endif]--&gt;&lt;style&gt; &lt;!--  /* Font Definitions */  @font-face 	{font-family:SimSun; 	panose-1:2 1 6 0 3 1 1 1 1 1; 	mso-font-alt:???????????????¡ì????????; 	mso-font-charset:134; 	mso-generic-font-family:auto; 	mso-font-pitch:variable; 	mso-font-signature:3 135135232 16 0 262145 0;} @font-face 	{font-family:"\@SimSun"; 	panose-1:2 1 6 0 3 1 1 1 1 1; 	mso-font-alt:"\@Arial Unicode MS"; 	mso-font-charset:134; 	mso-generic-font-family:auto; 	mso-font-pitch:variable; 	mso-font-signature:3 135135232 16 0 262145 0;}  /* Style Definitions */  p.MsoNormal, li.MsoNormal, div.MsoNormal 	{mso-style-parent:""; 	margin:0in; 	margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:12.0pt; 	font-family:"Times New Roman"; 	mso-fareast-font-family:"Times New Roman"; 	mso-fareast-language:EN-US;} @page Section1 	{size:8.5in 11.0in; 	margin:1.0in 1.25in 1.0in 1.25in; 	mso-header-margin:.5in; 	mso-footer-margin:.5in; 	mso-paper-source:0;} div.Section1 	{page:Section1;} --&gt; &lt;/style&gt;&lt;!--[if gte mso 10]&gt; &lt;style&gt;  /* Style Definitions */  table.MsoNormalTable 	{mso-style-name:"Table Normal"; 	mso-tstyle-rowband-size:0; 	mso-tstyle-colband-size:0; 	mso-style-noshow:yes; 	mso-style-parent:""; 	mso-padding-alt:0in 5.4pt 0in 5.4pt; 	mso-para-margin:0in; 	mso-para-margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:10.0pt; 	font-family:"Times New Roman"; 	mso-ansi-language:#0400; 	mso-fareast-language:#0400; 	mso-bidi-language:#0400;} &lt;/style&gt; &lt;![endif]--&gt;  &lt;div style=""&gt;  &lt;table vspace="0" width="505" cellpadding="0" cellspacing="0" height="70" hspace="0"&gt;  &lt;tbody&gt;&lt;tr&gt;   &lt;td style="padding: 0in 9.35pt;" valign="top" align="left" height="70"&gt;   &lt;div style="border: 1.5pt solid windowtext; padding: 1pt; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;This is the script to replace a particualr pattern   in the files. The script works recursively. This is actually combination of   the two scripts. as shown below.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;Just copy the above below in a file named &lt;span style=""&gt; &lt;/span&gt;“replaceInFile”&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt; color: blue;"&gt;#!/bin/sh&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt; color: blue;"&gt;#Script for replacing patterns in files&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt; color: blue;"&gt;numPar=$#&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt; color: blue;"&gt;pattern=$1&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt; color: blue;"&gt;text=$2&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt; color: blue;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt; color: blue;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt; color: blue;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt; color: blue;"&gt;if [ $numPar -gt 2 ]&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt; color: blue;"&gt;then&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt; color: blue;"&gt;&lt;span style=""&gt;        &lt;/span&gt;chmod 777 $3&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt; color: blue;"&gt;&lt;span style=""&gt;        &lt;/span&gt;printf "Replacing $1 by $2 in $3 ..."&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt; color: blue;"&gt;&lt;span style=""&gt;        &lt;/span&gt;sed -e "s/$pattern/$text/g" $3 1&gt;&gt; $3.new&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt; color: blue;"&gt;&lt;span style=""&gt;        &lt;/span&gt;mv $3 $3.bak&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt; color: blue;"&gt;&lt;span style=""&gt;        &lt;/span&gt;mv $3.new $3&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt; color: blue;"&gt;&lt;span style=""&gt;        &lt;/span&gt;echo "done."&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt; color: blue;"&gt;else&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt; color: blue;"&gt;&lt;span style=""&gt;     &lt;/span&gt;printf "repStr: invalid parameter count!\n"&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt; color: blue;"&gt;fi&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;This is the script which will actually perform the   replacement. It uses the “sed” command to perform the actual substitution.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;Now as we want the replacement to be done recursively   in a folder we will use another script which will give the filenames one by   one to this script.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;Copy the following code in the file named&lt;span style=""&gt;  &lt;/span&gt;replaceAll&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt; color: blue;"&gt;#!/bin/sh&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt; color: blue;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt; color: blue;"&gt;find . -name "*.cpp" &lt;span style=""&gt; &lt;/span&gt;-exec ./replaceInFile "&lt;&gt;" " &lt;&gt;" {} \;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;The above &lt;span style=""&gt; &lt;/span&gt;script will call the “replaceInFile” script   for each “.cpp” of the file in the directory. The patterns to be searched and   replaced should be mentioned in the breackets.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;Now copy both the scripts in the directory where   the replacement is to be done and just rin the replaceAll script. ( The   script generates &lt;span style=""&gt; &lt;/span&gt;“.bak” files as   backup )&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/div&gt;   &lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;  &lt;/div&gt;  &lt;!--[if !supportTextWrap]--&gt;&lt;br /&gt; &lt;!--[endif]--&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2938427049868690639-5194491038000155072?l=scriptingfaqs.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://scriptingfaqs.blogspot.com/feeds/5194491038000155072/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2938427049868690639&amp;postID=5194491038000155072' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2938427049868690639/posts/default/5194491038000155072'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2938427049868690639/posts/default/5194491038000155072'/><link rel='alternate' type='text/html' href='http://scriptingfaqs.blogspot.com/2008/07/script-for-replacing-string-in-file.html' title='Script for replacing string in file '/><author><name>Siebel Expert</name><uri>http://www.blogger.com/profile/11533458660230230361</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2938427049868690639.post-6700181113644875265</id><published>2008-07-31T01:15:00.000-07:00</published><updated>2008-12-23T03:54:08.334-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='VB Script'/><category scheme='http://www.blogger.com/atom/ns#' term='Scripting Language'/><title type='text'>Effective use of Macros using VB Script</title><content type='html'>&lt;meta equiv="Content-Type" content="text/html; charset=utf-8"&gt;&lt;meta name="ProgId" content="Word.Document"&gt;&lt;meta name="Generator" content="Microsoft Word 11"&gt;&lt;meta name="Originator" content="Microsoft Word 11"&gt;&lt;link rel="File-List" href="file:///D:%5CDOCUME%7E1%5Cshesu04%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C02%5Cclip_filelist.xml"&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;  &lt;o:documentproperties&gt;   &lt;o:author&gt;support&lt;/o:Author&gt;   &lt;o:version&gt;11.9999&lt;/o:Version&gt;  &lt;/o:DocumentProperties&gt; &lt;/xml&gt;&lt;![endif]--&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;  &lt;w:worddocument&gt;   &lt;w:view&gt;Normal&lt;/w:View&gt;   &lt;w:zoom&gt;0&lt;/w:Zoom&gt;   &lt;w:punctuationkerning/&gt;   &lt;w:validateagainstschemas/&gt;   &lt;w:saveifxmlinvalid&gt;false&lt;/w:SaveIfXMLInvalid&gt;   &lt;w:ignoremixedcontent&gt;false&lt;/w:IgnoreMixedContent&gt;   &lt;w:alwaysshowplaceholdertext&gt;false&lt;/w:AlwaysShowPlaceholderText&gt;   &lt;w:compatibility&gt;    &lt;w:breakwrappedtables/&gt;    &lt;w:snaptogridincell/&gt;    &lt;w:wraptextwithpunct/&gt;    &lt;w:useasianbreakrules/&gt;    &lt;w:dontgrowautofit/&gt;    &lt;w:usefelayout/&gt;   &lt;/w:Compatibility&gt;   &lt;w:browserlevel&gt;MicrosoftInternetExplorer4&lt;/w:BrowserLevel&gt;  &lt;/w:WordDocument&gt; &lt;/xml&gt;&lt;![endif]--&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;  &lt;w:latentstyles deflockedstate="false" latentstylecount="156"&gt;  &lt;/w:LatentStyles&gt; &lt;/xml&gt;&lt;![endif]--&gt;&lt;style&gt; &lt;!--  /* Font Definitions */  @font-face 	{font-family:SimSun; 	panose-1:2 1 6 0 3 1 1 1 1 1; 	mso-font-alt:???????????????¡ì????????; 	mso-font-charset:134; 	mso-generic-font-family:auto; 	mso-font-pitch:variable; 	mso-font-signature:3 135135232 16 0 262145 0;} @font-face 	{font-family:"\@SimSun"; 	panose-1:2 1 6 0 3 1 1 1 1 1; 	mso-font-alt:"\@Arial Unicode MS"; 	mso-font-charset:134; 	mso-generic-font-family:auto; 	mso-font-pitch:variable; 	mso-font-signature:3 135135232 16 0 262145 0;}  /* Style Definitions */  p.MsoNormal, li.MsoNormal, div.MsoNormal 	{mso-style-parent:""; 	margin:0in; 	margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:12.0pt; 	font-family:"Times New Roman"; 	mso-fareast-font-family:"Times New Roman"; 	mso-fareast-language:EN-US;} p.MsoBodyText, li.MsoBodyText, div.MsoBodyText 	{margin:0in; 	margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	background:white; 	border:none; 	mso-border-alt:solid windowtext 1.5pt; 	padding:0in; 	mso-padding-alt:1.0pt 1.0pt 1.0pt 1.0pt; 	mso-border-shadow:yes; 	mso-element:frame; 	mso-element-frame-width:369.75pt; 	mso-element-frame-height:52.85pt; 	mso-element-frame-hspace:9.35pt; 	mso-element-wrap:no-wrap-beside; 	mso-element-anchor-vertical:paragraph; 	mso-element-anchor-horizontal:page; 	mso-element-left:147.9pt; 	mso-element-top:2.85pt; 	font-size:10.0pt; 	mso-bidi-font-size:12.0pt; 	font-family:"Times New Roman"; 	mso-fareast-font-family:"Times New Roman"; 	mso-fareast-language:EN-US; 	font-weight:bold; 	mso-bidi-font-weight:normal;} @page Section1 	{size:8.5in 11.0in; 	margin:1.0in 1.25in 1.0in 1.25in; 	mso-header-margin:.5in; 	mso-footer-margin:.5in; 	mso-paper-source:0;} div.Section1 	{page:Section1;} --&gt; &lt;/style&gt;&lt;!--[if gte mso 10]&gt; &lt;style&gt;  /* Style Definitions */  table.MsoNormalTable 	{mso-style-name:"Table Normal"; 	mso-tstyle-rowband-size:0; 	mso-tstyle-colband-size:0; 	mso-style-noshow:yes; 	mso-style-parent:""; 	mso-padding-alt:0in 5.4pt 0in 5.4pt; 	mso-para-margin:0in; 	mso-para-margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:10.0pt; 	font-family:"Times New Roman"; 	mso-ansi-language:#0400; 	mso-fareast-language:#0400; 	mso-bidi-language:#0400;} &lt;/style&gt; &lt;![endif]--&gt;  &lt;div style=""&gt;  &lt;table vspace="0" width="505" cellpadding="0" cellspacing="0" height="70" hspace="0"&gt;  &lt;tbody&gt;&lt;tr&gt;   &lt;td style="padding: 0in 9.35pt;" valign="top" align="left" height="70"&gt;   &lt;div style="border: 1.5pt solid windowtext; padding: 1pt; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;Almost all of the microsoft products allow the   users to add their own macros. These macros are nothing but small programs written   using VBscrpit. The tasks which are to be done repeatedly can be recorded as a   macro and this macro can be executed to perform those tasks. You just have to   perform those steps once and record them as macros.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;e.g. Suppose you are writing a &lt;span style=""&gt; &lt;/span&gt;document which requires a few sentences to   be in red colour . Then you just have to perform the procedure once and   record it.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;What you have to do is:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;1) Go to the end of the line which is to be coloured.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;2)go to &lt;b style=""&gt;Tools-&gt;Macro-&gt;Record   New Macro&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;&lt;span style=""&gt;   &lt;/span&gt;A “Record   Macro” dialog appears.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;3) Give some suitable name to the macro.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;4) Now click on &lt;i style=""&gt;Keyboard &lt;span style=""&gt; &lt;/span&gt;&lt;/i&gt;&lt;span style=""&gt; &lt;/span&gt;button of the dilaog box and assign a short-cut   key for the macro. (usually you can assign&lt;span style=""&gt;    &lt;/span&gt;ctrl+ NUM PAD keys, as they are not assigned to any other shortcuts). &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;You can also add the macro shortcut to toolbar.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;5) Now when you click OK on the “Record Macro”   dialog a small window with Stop and Pause buttons appears. Now what ever   actions you perform will be recorded on a macro.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;As we want to colour a particualr line and our cursor   is at end of that line, select the whole line using &lt;span style=""&gt; &lt;/span&gt;“shift + home”, now go to the Font Color   menu and change the color as required. Now again go to the end of that line   and switch the colour back to the previous one (this is required so that the   next line is written in original colour only.). &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;6) Now press stop button on the “stop recording”   window. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoBodyText"&gt;All the actions you have done till now are recorded in the   macro and will be performed back when ever the macro is executed.&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;The macro is ready to be used.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;Now just go to end of any line, and press the   short cut keys that was assigned to the macro. That particualr line will be   coloured.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/div&gt;   &lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;  &lt;/div&gt;  &lt;!--[if !supportTextWrap]--&gt;&lt;br /&gt; &lt;!--[endif]--&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2938427049868690639-6700181113644875265?l=scriptingfaqs.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://scriptingfaqs.blogspot.com/feeds/6700181113644875265/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2938427049868690639&amp;postID=6700181113644875265' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2938427049868690639/posts/default/6700181113644875265'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2938427049868690639/posts/default/6700181113644875265'/><link rel='alternate' type='text/html' href='http://scriptingfaqs.blogspot.com/2008/07/effective-use-of-macros-using-vb-script.html' title='Effective use of Macros using VB Script'/><author><name>Siebel Expert</name><uri>http://www.blogger.com/profile/11533458660230230361</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2938427049868690639.post-1128686255189954799</id><published>2008-07-31T01:13:00.000-07:00</published><updated>2008-12-23T03:54:08.334-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Scripting Language'/><category scheme='http://www.blogger.com/atom/ns#' term='HTML'/><title type='text'>Documentation for the source code in HTML format.</title><content type='html'>&lt;meta equiv="Content-Type" content="text/html; charset=utf-8"&gt;&lt;meta name="ProgId" content="Word.Document"&gt;&lt;meta name="Generator" content="Microsoft Word 11"&gt;&lt;meta name="Originator" content="Microsoft Word 11"&gt;&lt;link rel="File-List" href="file:///D:%5CDOCUME%7E1%5Cshesu04%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C02%5Cclip_filelist.xml"&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;  &lt;o:documentproperties&gt;   &lt;o:author&gt;support&lt;/o:Author&gt;   &lt;o:version&gt;11.9999&lt;/o:Version&gt;  &lt;/o:DocumentProperties&gt; &lt;/xml&gt;&lt;![endif]--&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;  &lt;w:worddocument&gt;   &lt;w:view&gt;Normal&lt;/w:View&gt;   &lt;w:zoom&gt;0&lt;/w:Zoom&gt;   &lt;w:punctuationkerning/&gt;   &lt;w:validateagainstschemas/&gt;   &lt;w:saveifxmlinvalid&gt;false&lt;/w:SaveIfXMLInvalid&gt;   &lt;w:ignoremixedcontent&gt;false&lt;/w:IgnoreMixedContent&gt;   &lt;w:alwaysshowplaceholdertext&gt;false&lt;/w:AlwaysShowPlaceholderText&gt;   &lt;w:compatibility&gt;    &lt;w:breakwrappedtables/&gt;    &lt;w:snaptogridincell/&gt;    &lt;w:wraptextwithpunct/&gt;    &lt;w:useasianbreakrules/&gt;    &lt;w:dontgrowautofit/&gt;    &lt;w:usefelayout/&gt;   &lt;/w:Compatibility&gt;   &lt;w:browserlevel&gt;MicrosoftInternetExplorer4&lt;/w:BrowserLevel&gt;  &lt;/w:WordDocument&gt; &lt;/xml&gt;&lt;![endif]--&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;  &lt;w:latentstyles deflockedstate="false" latentstylecount="156"&gt;  &lt;/w:LatentStyles&gt; &lt;/xml&gt;&lt;![endif]--&gt;&lt;style&gt; &lt;!--  /* Font Definitions */  @font-face 	{font-family:SimSun; 	panose-1:2 1 6 0 3 1 1 1 1 1; 	mso-font-alt:???????????????¡ì????????; 	mso-font-charset:134; 	mso-generic-font-family:auto; 	mso-font-pitch:variable; 	mso-font-signature:3 135135232 16 0 262145 0;} @font-face 	{font-family:"\@SimSun"; 	panose-1:2 1 6 0 3 1 1 1 1 1; 	mso-font-alt:"\@Arial Unicode MS"; 	mso-font-charset:134; 	mso-generic-font-family:auto; 	mso-font-pitch:variable; 	mso-font-signature:3 135135232 16 0 262145 0;}  /* Style Definitions */  p.MsoNormal, li.MsoNormal, div.MsoNormal 	{mso-style-parent:""; 	margin:0in; 	margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:12.0pt; 	font-family:"Times New Roman"; 	mso-fareast-font-family:"Times New Roman"; 	mso-fareast-language:EN-US;} a:link, span.MsoHyperlink 	{color:blue; 	text-decoration:underline; 	text-underline:single;} a:visited, span.MsoHyperlinkFollowed 	{color:#606420; 	text-decoration:underline; 	text-underline:single;} @page Section1 	{size:8.5in 11.0in; 	margin:1.0in 1.25in 1.0in 1.25in; 	mso-header-margin:.5in; 	mso-footer-margin:.5in; 	mso-paper-source:0;} div.Section1 	{page:Section1;}  /* List Definitions */  @list l0 	{mso-list-id:1208493866; 	mso-list-type:simple; 	mso-list-template-ids:67698689;} @list l0:level1 	{mso-level-number-format:bullet; 	mso-level-text:; 	mso-level-tab-stop:.25in; 	mso-level-number-position:left; 	margin-left:.25in; 	text-indent:-.25in; 	font-family:Symbol;} @list l1 	{mso-list-id:1946694050; 	mso-list-type:simple; 	mso-list-template-ids:67698689;} @list l1:level1 	{mso-level-number-format:bullet; 	mso-level-text:; 	mso-level-tab-stop:.25in; 	mso-level-number-position:left; 	margin-left:.25in; 	text-indent:-.25in; 	font-family:Symbol;} ol 	{margin-bottom:0in;} ul 	{margin-bottom:0in;} --&gt; &lt;/style&gt;&lt;!--[if gte mso 10]&gt; &lt;style&gt;  /* Style Definitions */  table.MsoNormalTable 	{mso-style-name:"Table Normal"; 	mso-tstyle-rowband-size:0; 	mso-tstyle-colband-size:0; 	mso-style-noshow:yes; 	mso-style-parent:""; 	mso-padding-alt:0in 5.4pt 0in 5.4pt; 	mso-para-margin:0in; 	mso-para-margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:10.0pt; 	font-family:"Times New Roman"; 	mso-ansi-language:#0400; 	mso-fareast-language:#0400; 	mso-bidi-language:#0400;} &lt;/style&gt; &lt;![endif]--&gt;  &lt;div style=""&gt;  &lt;table vspace="0" width="505" cellpadding="0" cellspacing="0" height="70" hspace="0"&gt;  &lt;tbody&gt;&lt;tr&gt;   &lt;td style="padding: 0in 9.35pt;" valign="top" align="left" height="70"&gt;   &lt;div style="border: 1.5pt solid windowtext; padding: 1pt; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;&lt;br /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;The doxygen tool generates the documntation of   your in HTML format. The classes, files are listed separately. A list of all   the functions is generated. Also the documentation contains information like   which function is refered from which other fucntoins, the inheritance   diagrams etc. If you write the comments for the functions in a specific   format those comments are included in the documentation generated. ( for   example of the docuemntation generated for our project please visit &lt;a href="http://vayu/%7Eszref"&gt;&lt;span style="font-size: 12pt;"&gt;h&lt;span style=""&gt;t&lt;/span&gt;tp://v&lt;span style=""&gt;a&lt;/span&gt;yu/&lt;span style=""&gt;~&lt;/span&gt;s&lt;span style=""&gt;z&lt;/span&gt;ref/&lt;/span&gt;&lt;/a&gt;&lt;!--[if !supportNestedAnchors]--&gt;&lt;a name="_Hlt526845937"&gt;&lt;/a&gt;&lt;a name="_Hlt526845974"&gt;&lt;/a&gt;&lt;a name="_Hlt526845836"&gt;&lt;/a&gt;&lt;a name="_Hlt526845894"&gt;&lt;/a&gt;&lt;!--[endif]--&gt;&lt;span style=""&gt;  &lt;/span&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;A configuration file is required for the generating   the documentation in which you need to specify a few parameters. The   comfiguration file and the procedure to generate the docuemntation is present   in “SCG PhaseII/Development/Project Documents/References/Doxygen Documentation.”&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;With proper settings in the configuration file the   docuemntation can be generated in PDF format also.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;Aditional features:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; margin-left: 0.25in; text-indent: -0.25in; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;!--[if !supportLists]--&gt;&lt;span style="font-size: 10pt; font-family: Symbol;"&gt;&lt;span style=""&gt;·&lt;span style="font-family: &amp;quot;Times New Roman&amp;quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;           &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;&lt;span style="font-size: 10pt;"&gt;Include dependency graph:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;&lt;span style=""&gt;       &lt;/span&gt;For   generating the include dependancy graph the option &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;&lt;span style=""&gt;       &lt;/span&gt;ENABLE_PREPROCESSING   = YES&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;&lt;span style=""&gt;       &lt;/span&gt;MACRO_EXPANSION   = YES &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; margin-left: 0.25in; text-indent: -0.25in; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;!--[if !supportLists]--&gt;&lt;span style="font-size: 10pt; font-family: Symbol;"&gt;&lt;span style=""&gt;·&lt;span style="font-family: &amp;quot;Times New Roman&amp;quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;           &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;&lt;span style="font-size: 10pt;"&gt;Doxygen can be used to generate input for generation of .chm files   (Microsoft-style Help) by setting the "GENERATE_HTMLHELP" option to   "YES". This should be used as input for Microsoft HTML Help   Workshop.&lt;span style=""&gt;  &lt;/span&gt;This will provide the documentation   in the standard microsoft help format. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;&lt;span style=""&gt;        &lt;/span&gt;The   advantage of this help fornat is that, only the help file generated needs to be&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;&lt;span style=""&gt;       &lt;/span&gt;&lt;span style=""&gt; &lt;/span&gt;ported and not all the html pages generated.   It is also observed that the help file&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;&lt;span style=""&gt;       &lt;/span&gt;&lt;span style=""&gt; &lt;/span&gt;generated is highly compressed reducing the   size of documentation. The doxygen&lt;span style=""&gt;  &lt;/span&gt;tool&lt;span style=""&gt;  &lt;/span&gt;can be used to generate the doxygen   documentation of the code. As this documentation is in the html format, it is   very useful for study of the code.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/div&gt;   &lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;  &lt;/div&gt;  &lt;!--[if !supportTextWrap]--&gt;&lt;br /&gt; &lt;!--[endif]--&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2938427049868690639-1128686255189954799?l=scriptingfaqs.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://scriptingfaqs.blogspot.com/feeds/1128686255189954799/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2938427049868690639&amp;postID=1128686255189954799' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2938427049868690639/posts/default/1128686255189954799'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2938427049868690639/posts/default/1128686255189954799'/><link rel='alternate' type='text/html' href='http://scriptingfaqs.blogspot.com/2008/07/documentation-for-source-code-in-html.html' title='Documentation for the source code in HTML format.'/><author><name>Siebel Expert</name><uri>http://www.blogger.com/profile/11533458660230230361</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2938427049868690639.post-4511086238437762514</id><published>2008-07-31T01:12:00.000-07:00</published><updated>2008-12-23T03:54:08.334-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='VB Script'/><category scheme='http://www.blogger.com/atom/ns#' term='Scripting Language'/><title type='text'>Recording and writing own macro using vb script</title><content type='html'>&lt;meta equiv="Content-Type" content="text/html; charset=utf-8"&gt;&lt;meta name="ProgId" content="Word.Document"&gt;&lt;meta name="Generator" content="Microsoft Word 11"&gt;&lt;meta name="Originator" content="Microsoft Word 11"&gt;&lt;link rel="File-List" href="file:///D:%5CDOCUME%7E1%5Cshesu04%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C02%5Cclip_filelist.xml"&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;  &lt;o:documentproperties&gt;   &lt;o:author&gt;support&lt;/o:Author&gt;   &lt;o:version&gt;11.9999&lt;/o:Version&gt;  &lt;/o:DocumentProperties&gt; &lt;/xml&gt;&lt;![endif]--&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;  &lt;w:worddocument&gt;   &lt;w:view&gt;Normal&lt;/w:View&gt;   &lt;w:zoom&gt;0&lt;/w:Zoom&gt;   &lt;w:punctuationkerning/&gt;   &lt;w:validateagainstschemas/&gt;   &lt;w:saveifxmlinvalid&gt;false&lt;/w:SaveIfXMLInvalid&gt;   &lt;w:ignoremixedcontent&gt;false&lt;/w:IgnoreMixedContent&gt;   &lt;w:alwaysshowplaceholdertext&gt;false&lt;/w:AlwaysShowPlaceholderText&gt;   &lt;w:compatibility&gt;    &lt;w:breakwrappedtables/&gt;    &lt;w:snaptogridincell/&gt;    &lt;w:wraptextwithpunct/&gt;    &lt;w:useasianbreakrules/&gt;    &lt;w:dontgrowautofit/&gt;    &lt;w:usefelayout/&gt;   &lt;/w:Compatibility&gt;   &lt;w:browserlevel&gt;MicrosoftInternetExplorer4&lt;/w:BrowserLevel&gt;  &lt;/w:WordDocument&gt; &lt;/xml&gt;&lt;![endif]--&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;  &lt;w:latentstyles deflockedstate="false" latentstylecount="156"&gt;  &lt;/w:LatentStyles&gt; &lt;/xml&gt;&lt;![endif]--&gt;&lt;style&gt; &lt;!--  /* Font Definitions */  @font-face 	{font-family:SimSun; 	panose-1:2 1 6 0 3 1 1 1 1 1; 	mso-font-alt:???????????????¡ì????????; 	mso-font-charset:134; 	mso-generic-font-family:auto; 	mso-font-pitch:variable; 	mso-font-signature:3 135135232 16 0 262145 0;} @font-face 	{font-family:"\@SimSun"; 	panose-1:2 1 6 0 3 1 1 1 1 1; 	mso-font-alt:"\@Arial Unicode MS"; 	mso-font-charset:134; 	mso-generic-font-family:auto; 	mso-font-pitch:variable; 	mso-font-signature:3 135135232 16 0 262145 0;}  /* Style Definitions */  p.MsoNormal, li.MsoNormal, div.MsoNormal 	{mso-style-parent:""; 	margin:0in; 	margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:12.0pt; 	font-family:"Times New Roman"; 	mso-fareast-font-family:"Times New Roman"; 	mso-fareast-language:EN-US;} p.MsoBodyText, li.MsoBodyText, div.MsoBodyText 	{margin:0in; 	margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	border:none; 	mso-border-alt:solid windowtext 1.5pt; 	padding:0in; 	mso-padding-alt:1.0pt 1.0pt 1.0pt 1.0pt; 	mso-border-shadow:yes; 	mso-element:frame; 	mso-element-frame-width:369.75pt; 	mso-element-frame-height:52.85pt; 	mso-element-frame-hspace:9.35pt; 	mso-element-wrap:no-wrap-beside; 	mso-element-anchor-vertical:paragraph; 	mso-element-anchor-horizontal:page; 	mso-element-left:147.9pt; 	mso-element-top:2.85pt; 	font-size:12.0pt; 	font-family:"Times New Roman"; 	mso-fareast-font-family:"Times New Roman"; 	mso-fareast-language:EN-US;} @page Section1 	{size:8.5in 11.0in; 	margin:1.0in 1.25in 1.0in 1.25in; 	mso-header-margin:.5in; 	mso-footer-margin:.5in; 	mso-paper-source:0;} div.Section1 	{page:Section1;} --&gt; &lt;/style&gt;&lt;!--[if gte mso 10]&gt; &lt;style&gt;  /* Style Definitions */  table.MsoNormalTable 	{mso-style-name:"Table Normal"; 	mso-tstyle-rowband-size:0; 	mso-tstyle-colband-size:0; 	mso-style-noshow:yes; 	mso-style-parent:""; 	mso-padding-alt:0in 5.4pt 0in 5.4pt; 	mso-para-margin:0in; 	mso-para-margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:10.0pt; 	font-family:"Times New Roman"; 	mso-ansi-language:#0400; 	mso-fareast-language:#0400; 	mso-bidi-language:#0400;} &lt;/style&gt; &lt;![endif]--&gt;  &lt;div style=""&gt;  &lt;table vspace="0" width="505" cellpadding="0" cellspacing="0" height="70" hspace="0"&gt;  &lt;tbody&gt;&lt;tr&gt;   &lt;td style="padding: 0in 9.35pt;" valign="top" align="left" height="70"&gt;   &lt;div style="border: 1.5pt solid windowtext; padding: 1pt; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 11pt;"&gt;You can not only record a macro, but write your   own macro if you now a little bit of VB.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 11pt;"&gt;Here’s an example of how to write your own macro   in MSWORD.&lt;/span&gt;&lt;span style="font-size: 10pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoBodyText" style="background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;Suppose   you want the date to be in a format not provided by the word in the "Insert"   menu's date and time option, e.g.&lt;span style=""&gt;    &lt;/span&gt;dd.mm.yyyy. Then you could just write a small piece of VB code for   this. Just create a new macro and name ot “currentdate” then &lt;span style=""&gt; &lt;/span&gt;choose to edit it. The VB editor opens with   follwing code.&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="color: blue;"&gt;Sub currentdate()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="color: blue;"&gt;'&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="color: blue;"&gt;' currentdate &lt;span style=""&gt; &lt;/span&gt;Macro&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="color: blue;"&gt;' Macro recorded 02/09/01 by Amir Kamerkar&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="color: blue;"&gt;&lt;span style=""&gt;      &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="color: blue;"&gt;End Sub &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;This is nothing but the empty macro you just created now add the   piece of code as shown below.&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="color: blue;"&gt;Sub date2()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="color: blue;"&gt;'&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="color: blue;"&gt;' date2 Macro&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="color: blue;"&gt;' Macro recorded 02/09/01 by Kamerkar&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="color: red;"&gt;Dim MyDate&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="color: red;"&gt;&lt;span style=""&gt;      &lt;/span&gt;&lt;/span&gt;&lt;span style="color: red;" lang="FR"&gt;MyDate = Format(Date,   "dd.mm.yyyy")&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="color: red;" lang="FR"&gt;&lt;span style=""&gt;      &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="color: red;" lang="FR"&gt;&lt;span style=""&gt;      &lt;/span&gt;&lt;/span&gt;&lt;span style="color: red;"&gt;Selection.TypeText   Text:=MyDate &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="color: blue;"&gt;End Sub &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="font-size: 10pt;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="color: black;"&gt;The macro is ready for use.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class="MsoNormal" style="border: medium none ; padding: 0in; background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;&lt;span style="color: black;"&gt;You can change the format of the date by   changing the above code.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/div&gt;   &lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;  &lt;/div&gt;  &lt;!--[if !supportTextWrap]--&gt;&lt;br /&gt; &lt;!--[endif]--&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2938427049868690639-4511086238437762514?l=scriptingfaqs.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://scriptingfaqs.blogspot.com/feeds/4511086238437762514/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2938427049868690639&amp;postID=4511086238437762514' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2938427049868690639/posts/default/4511086238437762514'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2938427049868690639/posts/default/4511086238437762514'/><link rel='alternate' type='text/html' href='http://scriptingfaqs.blogspot.com/2008/07/recording-and-writing-own-macro-using.html' title='Recording and writing own macro using vb script'/><author><name>Siebel Expert</name><uri>http://www.blogger.com/profile/11533458660230230361</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2938427049868690639.post-8729362317803536917</id><published>2008-07-23T01:42:00.001-07:00</published><updated>2008-12-23T03:54:08.334-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Scripting Language'/><category scheme='http://www.blogger.com/atom/ns#' term='HTML'/><title type='text'>Internet generalities and an introduction to HTML: Question Paper – Part 1</title><content type='html'>&lt;meta equiv="Content-Type" content="text/html; charset=utf-8"&gt;&lt;meta name="ProgId" content="Word.Document"&gt;&lt;meta name="Generator" content="Microsoft Word 11"&gt;&lt;meta name="Originator" content="Microsoft Word 11"&gt;&lt;link rel="File-List" href="file:///D:%5CDOCUME%7E1%5Cshesu04%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C02%5Cclip_filelist.xml"&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;  &lt;o:documentproperties&gt;   &lt;o:author&gt;support&lt;/o:Author&gt;   &lt;o:version&gt;11.9999&lt;/o:Version&gt;  &lt;/o:DocumentProperties&gt; &lt;/xml&gt;&lt;![endif]--&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;  &lt;w:worddocument&gt;   &lt;w:view&gt;Normal&lt;/w:View&gt;   &lt;w:zoom&gt;0&lt;/w:Zoom&gt;   &lt;w:punctuationkerning/&gt;   &lt;w:validateagainstschemas/&gt;   &lt;w:saveifxmlinvalid&gt;false&lt;/w:SaveIfXMLInvalid&gt;   &lt;w:ignoremixedcontent&gt;false&lt;/w:IgnoreMixedContent&gt;   &lt;w:alwaysshowplaceholdertext&gt;false&lt;/w:AlwaysShowPlaceholderText&gt;   &lt;w:compatibility&gt;    &lt;w:breakwrappedtables/&gt;    &lt;w:snaptogridincell/&gt;    &lt;w:wraptextwithpunct/&gt;    &lt;w:useasianbreakrules/&gt;    &lt;w:dontgrowautofit/&gt;    &lt;w:usefelayout/&gt;   &lt;/w:Compatibility&gt;   &lt;w:browserlevel&gt;MicrosoftInternetExplorer4&lt;/w:BrowserLevel&gt;  &lt;/w:WordDocument&gt; &lt;/xml&gt;&lt;![endif]--&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;  &lt;w:latentstyles deflockedstate="false" latentstylecount="156"&gt;  &lt;/w:LatentStyles&gt; &lt;/xml&gt;&lt;![endif]--&gt;&lt;style&gt; &lt;!--  /* Font Definitions */  @font-face 	{font-family:SimSun; 	panose-1:2 1 6 0 3 1 1 1 1 1; 	mso-font-alt:ËÎÌå; 	mso-font-charset:134; 	mso-generic-font-family:auto; 	mso-font-pitch:variable; 	mso-font-signature:3 135135232 16 0 262145 0;} @font-face 	{font-family:"\@SimSun"; 	panose-1:2 1 6 0 3 1 1 1 1 1; 	mso-font-alt:"\@Arial Unicode MS"; 	mso-font-charset:134; 	mso-generic-font-family:auto; 	mso-font-pitch:variable; 	mso-font-signature:3 135135232 16 0 262145 0;}  /* Style Definitions */  p.MsoNormal, li.MsoNormal, div.MsoNormal 	{mso-style-parent:""; 	margin:0in; 	margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:12.0pt; 	font-family:"Times New Roman"; 	mso-fareast-font-family:"Times New Roman"; 	mso-ansi-language:ES-AR; 	mso-fareast-language:ES-AR;} @page Section1 	{size:595.35pt 842.0pt; 	margin:56.7pt 42.55pt 56.7pt 56.7pt; 	mso-header-margin:35.45pt; 	mso-footer-margin:35.45pt; 	mso-paper-source:0;} div.Section1 	{page:Section1;} --&gt; &lt;/style&gt;&lt;!--[if gte mso 10]&gt; &lt;style&gt;  /* Style Definitions */  table.MsoNormalTable 	{mso-style-name:"Table Normal"; 	mso-tstyle-rowband-size:0; 	mso-tstyle-colband-size:0; 	mso-style-noshow:yes; 	mso-style-parent:""; 	mso-padding-alt:0in 5.4pt 0in 5.4pt; 	mso-para-margin:0in; 	mso-para-margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:10.0pt; 	font-family:"Times New Roman"; 	mso-ansi-language:#0400; 	mso-fareast-language:#0400; 	mso-bidi-language:#0400;} &lt;/style&gt; &lt;![endif]--&gt;&lt;span style=""&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;1-Provide a brief description of the INTERNET.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;It’s a world wide collection of computer networks. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;2-What makes the internet different from other networks?&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;Its world wide collection of digital telecommunication links that share a common set of computer-network technologies, protocols and applications.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;3-A) Distinguish between INTRANETS and EXTRANETS B) What is the relationship between intranets - extranets and the internet? Explain.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;Intranet: they are private networks usually unconnected to outside institutional boundaries and with restricted access to member of the institution.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;Extranet: semi-private networks that restrict access, but use the internet to provide services to members.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;Both of them use the same software, applications and networking protocols of the Internet.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;In contrast with both of these, the Internet has no restrictions, and it is not well organized, it may take some time to get experience and learn how to work with it taking advantage of all its conveniences.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;4-What was the reason for the creation of the first prototype of the internet (ARPAnet)?&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;The ARP Anet was created as a result of a project that had for goal to create a network of computers that could withstand the loss of several machines due to the wars, and maintain connection and communication.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;5-Explain the two different ways in which an individual computer is identified in the internet.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;Individual computers can be identified in the internet because any computer connected to it has its own address: a number whose format is identified by the internet protocol.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;Each computer in the internet has also its own name selected by its owner. The name becomes unique when append, like surnames, all of the machines domain names as a period- separated suffix, creating a fully qualified domain name. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;6-What are CLIENTS, SERVERS and BROWSERS? Explain the functions of each.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;Servers and clients are two types of computers. Servers serve up documents and clients retrieve and display up documents for people. On the other hand, browsers are programs used to access and display HTML documents and also access and retrieve electronic documents.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;&lt;span style=""&gt; &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;7-Describe the FLOW OF INFORMATION in the internet.&lt;span style=""&gt;  &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;u&gt;&lt;span style=""&gt;Flow of information in the internet&lt;/span&gt;&lt;/u&gt;&lt;span style=""&gt;: Some people take the view that the flow of information on the internet should not be regulated, in order to encourage freedom of expression and protection of secrecy. Others believe that the flow of illegal or harmful information should be banned, and that the flow of information on the internet should be regulated to ensure the protection of privacy.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-left: 0.25in;"&gt;&lt;span style=""&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style=""&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;span style=""&gt;__________&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2938427049868690639-8729362317803536917?l=scriptingfaqs.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://scriptingfaqs.blogspot.com/feeds/8729362317803536917/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2938427049868690639&amp;postID=8729362317803536917' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2938427049868690639/posts/default/8729362317803536917'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2938427049868690639/posts/default/8729362317803536917'/><link rel='alternate' type='text/html' href='http://scriptingfaqs.blogspot.com/2008/07/internet-generalities-and-introduction.html' title='Internet generalities and an introduction to HTML: Question Paper – Part 1'/><author><name>Siebel Expert</name><uri>http://www.blogger.com/profile/11533458660230230361</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2938427049868690639.post-6435018884640150148</id><published>2008-07-07T19:36:00.000-07:00</published><updated>2008-12-23T03:54:08.334-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='PHP'/><category scheme='http://www.blogger.com/atom/ns#' term='Scripting Language'/><title type='text'>PHP Interview Questions And Answers Set II</title><content type='html'>What's PHP&lt;br /&gt;The PHP Hypertext Preprocessor is a programming language that allows web developers to create dynamic content that interacts with databases. PHP is basically used for developing web based software applications.&lt;br /&gt;&lt;br /&gt;What Is a Session?&lt;br /&gt;A session is a logical object created by the PHP engine to allow you to preserve data across subsequent HTTP requests.&lt;br /&gt;There is only one session object available to your PHP scripts at any time. Data saved to the session by a script can be retrieved by the same script or another script when requested from the same visitor.&lt;br /&gt;Sessions are commonly used to store temporary data to allow multiple PHP pages to offer a complete functional transaction for the same visitor.&lt;br /&gt;&lt;br /&gt;What is meant by PEAR in php?&lt;br /&gt;Answer1:&lt;br /&gt;PEAR is the next revolution in PHP. This repository is bringing higher level programming to PHP. PEAR is a framework and distribution system for reusable PHP components. It eases installation by bringing an automated wizard, and packing the strength and experience of PHP users into a nicely organised OOP library. PEAR also provides a command-line interface that can be used to automatically install "packages"&lt;br /&gt;&lt;br /&gt;Answer2:&lt;br /&gt;PEAR is short for "PHP Extension and Application Repository" and is pronounced just like the fruit. The purpose of PEAR is to provide:&lt;br /&gt;A structured library of open-sourced code for PHP users&lt;br /&gt;A system for code distribution and package maintenance&lt;br /&gt;A standard style for code written in PHP&lt;br /&gt;The PHP Foundation Classes (PFC),&lt;br /&gt;The PHP Extension Community Library (PECL),&lt;br /&gt;A web site, mailing lists and download mirrors to support the PHP/PEAR community&lt;br /&gt;PEAR is a community-driven project with the PEAR Group as the governing body. The project has been founded by Stig S. Bakken in 1999 and quite a lot of people have joined the project since then.&lt;br /&gt;&lt;br /&gt;How can we know the number of days between two given dates using PHP?&lt;br /&gt;Simple arithmetic:&lt;br /&gt;&lt;br /&gt;$date1 = date('Y-m-d');&lt;br /&gt;$date2 = '2006-07-01';&lt;br /&gt;$days = (strtotime() - strtotime()) / (60 * 60 * 24);&lt;br /&gt;echo "Number of days since '2006-07-01': $days";&lt;br /&gt;&lt;br /&gt;How can we repair a MySQL table?&lt;br /&gt;The syntex for repairing a mysql table is:&lt;br /&gt;&lt;br /&gt;REPAIR TABLE tablename&lt;br /&gt;REPAIR TABLE tablename QUICK&lt;br /&gt;REPAIR TABLE tablename EXTENDED&lt;br /&gt;&lt;br /&gt;This command will repair the table specified.&lt;br /&gt;If QUICK is given, MySQL will do a repair of only the index tree.&lt;br /&gt;If EXTENDED is given, it will create index row by row.&lt;br /&gt;&lt;br /&gt;What is the difference between $message and $$message?&lt;br /&gt;Anwser 1:&lt;br /&gt;$message is a simple variable whereas $$message is a reference variable. Example:&lt;br /&gt;$user = 'bob'&lt;br /&gt;&lt;br /&gt;is equivalent to&lt;br /&gt;&lt;br /&gt;$holder = 'user';&lt;br /&gt;$$holder = 'bob';&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Anwser 2:&lt;br /&gt;They are both variables. But $message is a variable with a fixed name. $$message is a variable who's name is stored in $message. For example, if $message contains "var", $$message is the same as $var.&lt;br /&gt;&lt;br /&gt;What Is a Persistent Cookie?&lt;br /&gt;A persistent cookie is a cookie which is stored in a cookie file permanently on the browser's computer. By default, cookies are created as temporary cookies which stored only in the browser's memory. When the browser is closed, temporary cookies will be erased. You should decide when to use temporary cookies and when to use persistent cookies based on their differences:&lt;br /&gt; Temporary cookies can not be used for tracking long-term information.&lt;br /&gt; Persistent cookies can be used for tracking long-term information.&lt;br /&gt; Temporary cookies are safer because no programs other than the browser can access them.&lt;br /&gt;&lt;br /&gt; Persistent cookies are less secure because users can open cookie files see the cookie values.&lt;br /&gt;&lt;br /&gt;What does a special set of tags &lt;?= and ?&gt; do in PHP?&lt;br /&gt;The output is displayed directly to the browser.&lt;br /&gt;&lt;br /&gt;How do you define a constant?&lt;br /&gt;Via define() directive, like define ("MYCONSTANT", 100);&lt;br /&gt;How To Write the FORM Tag Correctly for Uploading Files?&lt;br /&gt;When users clicks the submit button, files specified in the &lt;input type="FILE..."&gt; will be transferred from the browser to the Web server. This transferring (uploading) process is controlled by a properly written &lt;form...&gt; tag as:&lt;br /&gt;  &lt;form action="receiving.php" method="post" enctype="multipart/form-data"&gt;&lt;br /&gt;Note that you must specify METHOD as "post" and ENCTYPE as "multipart/form-data" in order for the uploading process to work. The following PHP code, called logo_upload.php, shows you a complete FORM tag for file uploading:&lt;br /&gt;&lt;?php&lt;br /&gt;  print("&lt;html&gt;&lt;form action=processing_uploaded_files.php"&lt;br /&gt;    ." method=post enctype=multipart/form-data&gt;\n");&lt;br /&gt;  print("Please submit an image file a Web site logo for"&lt;br /&gt;    ." fyicenter.com:&lt;br /&gt;\n");&lt;br /&gt;  print("&lt;input type="file" name="fyicenter_logo"&gt;&lt;br /&gt;\n");&lt;br /&gt;  print("&lt;input type="submit"&gt;\n");&lt;br /&gt;  print("&lt;/form&gt;&lt;/html&gt;\n");&lt;br /&gt;?&gt;&lt;br /&gt;&lt;br /&gt;What are the differences between require and include, include_once?&lt;br /&gt;Anwser 1:&lt;br /&gt;require_once() and include_once() are both the functions to include and evaluate the specified file only once. If the specified file is included previous to the present call occurrence, it will not be done again.&lt;br /&gt;&lt;br /&gt;But require() and include() will do it as many times they are asked to do.&lt;br /&gt;&lt;br /&gt;Anwser 2:&lt;br /&gt;The include_once() statement includes and evaluates the specified file during the execution of the script. This is a behavior similar to the include() statement, with the only difference being that if the code from a file has already been included, it will not be included again. The major difference between include() and require() is that in failure include() produces a warning message whereas require() produces a fatal errors.&lt;br /&gt;&lt;br /&gt;Anwser 3:&lt;br /&gt;All three are used to an include file into the current page.&lt;br /&gt;If the file is not present, require(), calls a fatal error, while in include() does not.&lt;br /&gt;The include_once() statement includes and evaluates the specified file during the execution of the script. This is a behavior similar to the include() statement, with the only difference being that if the code from a file has already been included, it will not be included again. It des not call a fatal error if file not exists. require_once() does the same as include_once(), but it calls a fatal error if file not exists.&lt;br /&gt;&lt;br /&gt;Anwser 4:&lt;br /&gt;File will not be included more than once. If we want to include a file once only and further calling of the file will be ignored then we have to use the PHP function include_once(). This will prevent problems with function redefinitions, variable value reassignments, etc.&lt;br /&gt;&lt;br /&gt;What is meant by urlencode and urldecode?&lt;br /&gt;Anwser 1:&lt;br /&gt;urlencode() returns the URL encoded version of the given string. URL coding converts special characters into % signs followed by two hex digits. For example: urlencode("10.00%") will return "10%2E00%25". URL encoded strings are safe to be used as part of URLs.&lt;br /&gt;urldecode() returns the URL decoded version of the given string.&lt;br /&gt;&lt;br /&gt;Anwser 2:&lt;br /&gt;string urlencode(str) - Returns the URL encoded version of the input string. String values to be used in URL query string need to be URL encoded. In the URL encoded version:&lt;br /&gt;&lt;br /&gt;Alphanumeric characters are maintained as is.&lt;br /&gt;Space characters are converted to "+" characters.&lt;br /&gt;Other non-alphanumeric characters are converted "%" followed by two hex digits representing the converted character.&lt;br /&gt;&lt;br /&gt;string urldecode(str) - Returns the original string of the input URL encoded string.&lt;br /&gt;&lt;br /&gt;For example:&lt;br /&gt;&lt;br /&gt;$discount ="10.00%";&lt;br /&gt;$url = "http://domain.com/submit.php?disc=".urlencode($discount);&lt;br /&gt;echo $url;&lt;br /&gt;&lt;br /&gt;You will get "http://domain.com/submit.php?disc=10%2E00%25".&lt;br /&gt;&lt;br /&gt;How To Get the Uploaded File Information in the Receiving Script?&lt;br /&gt;Once the Web server received the uploaded file, it will call the PHP script specified in the form action attribute to process them. This receiving PHP script can get the uploaded file information through the predefined array called $_FILES. Uploaded file information is organized in $_FILES as a two-dimensional array as:&lt;br /&gt; $_FILES[$fieldName]['name'] - The Original file name on the browser system.&lt;br /&gt; $_FILES[$fieldName]['type'] - The file type determined by the browser.&lt;br /&gt; $_FILES[$fieldName]['size'] - The Number of bytes of the file content.&lt;br /&gt; $_FILES[$fieldName]['tmp_name'] - The temporary filename of the file in which the uploaded file was stored on the server.&lt;br /&gt; $_FILES[$fieldName]['error'] - The error code associated with this file upload.&lt;br /&gt;The $fieldName is the name used in the &lt;input type="FILE," name="fieldName"&gt;.&lt;br /&gt;&lt;br /&gt;What is the difference between mysql_fetch_object and mysql_fetch_array?&lt;br /&gt;MySQL fetch object will collect first single matching record where mysql_fetch_array will collect all matching records from the table in an array&lt;br /&gt;&lt;br /&gt;How can I execute a PHP script using command line?&lt;br /&gt;Just run the PHP CLI (Command Line Interface) program and provide the PHP script file name as the command line argument. For example, "php myScript.php", assuming "php" is the command to invoke the CLI program.&lt;br /&gt;Be aware that if your PHP script was written for the Web CGI interface, it may not execute properly in command line environment.&lt;br /&gt;&lt;br /&gt;I am trying to assign a variable the value of 0123, but it keeps coming up with a different number, what’s the problem?&lt;br /&gt;PHP Interpreter treats numbers beginning with 0 as octal. Look at the similar PHP interview questions for more numeric problems.&lt;br /&gt;&lt;br /&gt;Would I use print "$a dollars" or "{$a} dollars" to print out the amount of dollars in this example?&lt;br /&gt;In this example it wouldn’t matter, since the variable is all by itself, but if you were to print something like "{$a},000,000 mln dollars", then you definitely need to use the braces.&lt;br /&gt;&lt;br /&gt;What are the different tables present in MySQL? Which type of table is generated when we are creating a table in the following syntax: create table employee(eno int(2),ename varchar(10))?&lt;br /&gt;Total 5 types of tables we can create&lt;br /&gt;1. MyISAM&lt;br /&gt;2. Heap&lt;br /&gt;3. Merge&lt;br /&gt;4. INNO DB&lt;br /&gt;5. ISAM&lt;br /&gt;MyISAM is the default storage engine as of MySQL 3.23. When you fire the above create query MySQL will create a MyISAM table.&lt;br /&gt;&lt;br /&gt;How To Create a Table?&lt;br /&gt;If you want to create a table, you can run the CREATE TABLE statement as shown in the following sample script:&lt;br /&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;include "mysql_connection.php";&lt;br /&gt;&lt;br /&gt;$sql = "CREATE TABLE fyi_links ("&lt;br /&gt;. " id INTEGER NOT NULL"&lt;br /&gt;. ", url VARCHAR(80) NOT NULL"&lt;br /&gt;. ", notes VARCHAR(1024)"&lt;br /&gt;. ", counts INTEGER"&lt;br /&gt;. ", time TIMESTAMP DEFAULT sysdate()"&lt;br /&gt;. ")";&lt;br /&gt;if (mysql_query($sql, $con)) {&lt;br /&gt;print("Table fyi_links created.\n");&lt;br /&gt;} else {&lt;br /&gt;print("Table creation failed.\n");&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;mysql_close($con);&lt;br /&gt;?&gt;&lt;br /&gt;&lt;br /&gt;Remember that mysql_query() returns TRUE/FALSE on CREATE statements. If you run this script, you will get something like this:&lt;br /&gt;Table fyi_links created.&lt;br /&gt;&lt;br /&gt;How can we encrypt the username and password using PHP?&lt;br /&gt;Answer1&lt;br /&gt;You can encrypt a password with the following Mysql&gt;SET PASSWORD=PASSWORD("Password");&lt;br /&gt;&lt;br /&gt;Answer2&lt;br /&gt;You can use the MySQL PASSWORD() function to encrypt username and password. For example,&lt;br /&gt;INSERT into user (password, ...) VALUES (PASSWORD($password”)), ...);&lt;br /&gt;&lt;br /&gt;How do you pass a variable by value?&lt;br /&gt;Just like in C++, put an ampersand in front of it, like $a = &amp;amp;$b&lt;br /&gt;&lt;br /&gt;WHAT IS THE FUNCTIONALITY OF THE FUNCTIONS STRSTR() AND STRISTR()?&lt;br /&gt;string strstr ( string haystack, string needle ) returns part of haystack string from the first occurrence of needle to the end of haystack. This function is case-sensitive.&lt;br /&gt;&lt;br /&gt;stristr() is idential to strstr() except that it is case insensitive.&lt;br /&gt;&lt;br /&gt;When are you supposed to use endif to end the conditional statement?&lt;br /&gt;When the original if was followed by : and then the code block without braces.&lt;br /&gt;&lt;br /&gt;How can we send mail using JavaScript?&lt;br /&gt;No. There is no way to send emails directly using JavaScript.&lt;br /&gt;&lt;br /&gt;But you can use JavaScript to execute a client side email program send the email using the "mailto" code. Here is an example:&lt;br /&gt;&lt;br /&gt;function myfunction(form)&lt;br /&gt;{&lt;br /&gt;tdata=document.myform.tbox1.value;&lt;br /&gt;location="mailto:mailid@domain.com?subject=...";&lt;br /&gt;return true;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;What is the functionality of the function strstr and stristr?&lt;br /&gt;strstr() returns part of a given string from the first occurrence of a given substring to the end of the string. For example: strstr("user@example.com","@") will return "@example.com".&lt;br /&gt;stristr() is idential to strstr() except that it is case insensitive.&lt;br /&gt;&lt;br /&gt;What is the difference between ereg_replace() and eregi_replace()?&lt;br /&gt;eregi_replace() function is identical to ereg_replace() except that it ignores case distinction when matching alphabetic characters.&lt;br /&gt;&lt;br /&gt;How do I find out the number of parameters passed into function9. ?&lt;br /&gt;func_num_args() function returns the number of parameters passed in.&lt;br /&gt;&lt;br /&gt;What is the purpose of the following files having extensions: frm, myd, and myi? What these files contain?&lt;br /&gt;In MySQL, the default table type is MyISAM.&lt;br /&gt;Each MyISAM table is stored on disk in three files. The files have names that begin with the table name and have an extension to indicate the file type.&lt;br /&gt;&lt;br /&gt;The '.frm' file stores the table definition.&lt;br /&gt;The data file has a '.MYD' (MYData) extension.&lt;br /&gt;The index file has a '.MYI' (MYIndex) extension,&lt;br /&gt;&lt;br /&gt;If the variable $a is equal to 5 and variable $b is equal to character a, what’s the value of $$b?&lt;br /&gt;100, it’s a reference to existing variable.&lt;br /&gt;&lt;br /&gt;Write a query for the following question&lt;br /&gt;The table tbl_sites contains the following data:&lt;br /&gt;&lt;br /&gt;-----------------------------------------------------&lt;br /&gt;Userid sitename country&lt;br /&gt;------------------------------------------------------&lt;br /&gt;1 sureshbabu indian&lt;br /&gt;2 PHPprogrammer andhra&lt;br /&gt;3 PHP.net usa&lt;br /&gt;4 PHPtalk.com germany&lt;br /&gt;5 MySQL.com usa&lt;br /&gt;6 sureshbabu canada&lt;br /&gt;7 PHPbuddy.com pakistan&lt;br /&gt;8. PHPtalk.com austria&lt;br /&gt;9. PHPfreaks.com sourthafrica&lt;br /&gt;10. PHPsupport.net russia&lt;br /&gt;11. sureshbabu australia&lt;br /&gt;12. sureshbabu nepal&lt;br /&gt;13. PHPtalk.com italy&lt;br /&gt;&lt;br /&gt;Write a select query that will be displayed the duplicated site name and how many times it is duplicated? …&lt;br /&gt;SELECT sitename, COUNT(*) AS NumOccurrences&lt;br /&gt;FROM tbl_sites&lt;br /&gt;GROUP BY sitename HAVING COUNT(*) &gt; 1&lt;br /&gt;&lt;br /&gt;How To Protect Special Characters in Query String?&lt;br /&gt;If you want to include special characters like spaces in the query string, you need to protect them by applying the urlencode() translation function. The script below shows how to use urlencode():&lt;br /&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;print("&lt;html&gt;");&lt;br /&gt;print("&lt;p&gt;Please click the links below"&lt;br /&gt;." to submit comments about FYICenter.com:&lt;/p&gt;");&lt;br /&gt;$comment = 'I want to say: "It\'s a good site! :-&gt;"';&lt;br /&gt;$comment = urlencode($comment);&lt;br /&gt;print("&lt;p&gt;"&lt;br /&gt;."&lt;a href="\" name="Guest&amp;amp;comment="$comment\"&gt;"&lt;br /&gt;."It's an excellent site!&lt;/a&gt;&lt;/p&gt;");&lt;br /&gt;$comment = 'This visitor said: "It\'s an average site! :-("';&lt;br /&gt;$comment = urlencode($comment);&lt;br /&gt;print("&lt;p&gt;"&lt;br /&gt;.'&lt;a href="processing_forms.php?'.$comment.'"&gt;'&lt;br /&gt;."It's an average site.&lt;/a&gt;&lt;/p&gt;");&lt;br /&gt;print("&lt;/html&gt;");&lt;br /&gt;?&gt;&lt;br /&gt;&lt;br /&gt;Are objects passed by value or by reference?&lt;br /&gt;Everything is passed by value.&lt;br /&gt;&lt;br /&gt;What are the differences between DROP a table and TRUNCATE a table?&lt;br /&gt;DROP TABLE table_name - This will delete the table and its data.&lt;br /&gt;&lt;br /&gt;TRUNCATE TABLE table_name - This will delete the data of the table, but not the table definition.&lt;br /&gt;&lt;br /&gt;What are the differences between GET and POST methods in form submitting, give the case where we can use GET and we can use POST methods?&lt;br /&gt;Anwser 1:&lt;br /&gt;&lt;br /&gt;When we submit a form, which has the GET method it displays pair of name/value used in the form at the address bar of the browser preceded by url. Post method doesn't display these values.&lt;br /&gt;&lt;br /&gt;Anwser 2:&lt;br /&gt;&lt;br /&gt;When you want to send short or small data, not containing ASCII characters, then you can use GET” Method. But for long data sending, say more then 100 character you can use POST method.&lt;br /&gt;&lt;br /&gt;Once most important difference is when you are sending the form with GET method. You can see the output which you are sending in the address bar. Whereas if you send the form with POST” method then user can not see that information.&lt;br /&gt;&lt;br /&gt;Anwser 3:&lt;br /&gt;&lt;br /&gt;What are "GET" and "POST"?&lt;br /&gt;&lt;br /&gt;GET and POST are methods used to send data to the server: With the GET method, the browser appends the data onto the URL. With the Post method, the data is sent as "standard input."&lt;br /&gt;&lt;br /&gt;Major Difference&lt;br /&gt;&lt;br /&gt;In simple words, in POST method data is sent by standard input (nothing shown in URL when posting while in GET method data is sent through query string.&lt;br /&gt;&lt;br /&gt;Ex: Assume we are logging in with username and password.&lt;br /&gt;&lt;br /&gt;GET: we are submitting a form to login.php, when we do submit or similar action, values are sent through visible query string (notice ./login.php?username=...&amp;amp;password=... as URL when executing the script login.php) and is retrieved by login.php by $_GET['username'] and $_GET['password'].&lt;br /&gt;&lt;br /&gt;POST: we are submitting a form to login.php, when we do submit or similar action, values are sent through invisible standard input (notice ./login.php) and is retrieved by login.php by $_POST['username'] and $_POST['password'].&lt;br /&gt;&lt;br /&gt;POST is assumed more secure and we can send lot more data than that of GET method is limited (they say Internet Explorer can take care of maximum 2083 character as a query string).&lt;br /&gt;&lt;br /&gt;Anwser 4:&lt;br /&gt;&lt;br /&gt;In the get method the data made available to the action page ( where data is received ) by the URL so data can be seen in the address bar. Not advisable if you are sending login info like password etc. In the post method the data will be available as data blocks and not as query string in case of get method.&lt;br /&gt;&lt;br /&gt;Anwser 5:&lt;br /&gt;&lt;br /&gt;When we submit a form, which has the GET method it pass value in the form of query string (set of name/value pair) and display along with URL. With GET we can a small data submit from the form (a set of 255 character) whereas Post method doesn't display value with URL. It passes value in the form of Object and we can submit large data from the form.&lt;br /&gt;&lt;br /&gt;Anwser 6:&lt;br /&gt;&lt;br /&gt;On the server side, the main difference between GET and POST is where the submitted is stored. The $_GET array stores data submitted by the GET method. The $_POST array stores data submitted by the POST method.&lt;br /&gt;On the browser side, the difference is that data submitted by the GET method will be displayed in the browser’s address field. Data submitted by the POST method will not be displayed anywhere on the browser.&lt;br /&gt;GET method is mostly used for submitting a small amount and less sensitive data. POST method is mostly used for submitting a large amount or sensitive data.&lt;br /&gt;&lt;br /&gt;How do you call a constructor for a parent class?&lt;br /&gt;parent::constructor($value)&lt;br /&gt;&lt;br /&gt;WHAT ARE THE DIFFERENT TYPES OF ERRORS IN PHP?&lt;br /&gt;Here are three basic types of runtime errors in PHP:&lt;br /&gt;&lt;br /&gt;1. Notices: These are trivial, non-critical errors that PHP encounters while executing a script - for example, accessing a variable that has not yet been defined. By default, such errors are not displayed to the user at all - although you can change this default behavior.&lt;br /&gt;&lt;br /&gt;2. Warnings: These are more serious errors - for example, attempting to include() a file which does not exist. By default, these errors are displayed to the user, but they do not result in script termination.&lt;br /&gt;&lt;br /&gt;3. Fatal errors: These are critical errors - for example, instantiating an object of a non-existent class, or calling a non-existent function. These errors cause the immediate termination of the script, and PHP's default behavior is to display them to the user when they take place.&lt;br /&gt;&lt;br /&gt;Internally, these variations are represented by twelve different error types&lt;br /&gt;&lt;br /&gt;What’s the special meaning of __sleep and __wakeup?&lt;br /&gt;__sleep returns the array of all the variables than need to be saved, while __wakeup retrieves them.&lt;br /&gt;&lt;br /&gt;How can we submit a form without a submit button?&lt;br /&gt;If you don't want to use the Submit button to submit a form, you can use normal hyper links to submit a form. But you need to use some JavaScript code in the URL of the link. For example:&lt;br /&gt;&lt;br /&gt;&lt;a href="javascript: document.myform.submit();"&gt;Submit Me&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Why doesn’t the following code print the newline properly? &lt;?php $str = ‘Hello, there.\nHow are you?\nThanks for visiting fyicenter’; print $str; ?&gt;&lt;br /&gt;Because inside the single quotes the \n character is not interpreted as newline, just as a sequence of two characters - \ and n.&lt;br /&gt;&lt;br /&gt;Would you initialize your strings with single quotes or double quotes?&lt;br /&gt;Since the data inside the single-quoted string is not parsed for variable substitution, it’s always a better idea speed-wise to initialize a string with single quotes, unless you specifically need variable substitution.&lt;br /&gt;&lt;br /&gt;How can we extract string 'abc.com ' from a string http://info@abc.com using regular expression of php?&lt;br /&gt;We can use the preg_match() function with "/.*@(.*)$/" as&lt;br /&gt;the regular expression pattern. For example:&lt;br /&gt;preg_match("/.*@(.*)$/","http://info@abc.com",$data);&lt;br /&gt;echo $data[1];&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;What is the difference between the functions unlink and unset?&lt;br /&gt;unlink() is a function for file system handling. It will simply delete the file in context.&lt;br /&gt;&lt;br /&gt;unset() is a function for variable management. It will make a variable undefined.&lt;br /&gt;&lt;br /&gt;How come the code works, but doesn’t for two-dimensional array of mine?&lt;br /&gt;Any time you have an array with more than one dimension, complex parsing syntax is required. print "Contents: {$arr[1][2]}" would’ve worked.&lt;br /&gt;&lt;br /&gt;How can we register the variables into a session?&lt;br /&gt;session_register($session_var);&lt;br /&gt;&lt;br /&gt;$_SESSION['var'] = 'value';&lt;br /&gt;&lt;br /&gt;What is the difference between characters \023 and \x23?&lt;br /&gt;The first one is octal 23, the second is hex 23.&lt;br /&gt;&lt;br /&gt;With a heredoc syntax, do I get variable substitution inside the heredoc contents?&lt;br /&gt;Yes.&lt;br /&gt;&lt;br /&gt;How can we submit form without a submit button?&lt;br /&gt;We can use a simple JavaScript code linked to an event trigger of any form field. In the JavaScript code, we can call the document.form.submit() function to submit the form. For example: &lt;input type="button" value="Save" onclick="document.form.submit()"&gt;&lt;br /&gt;&lt;br /&gt;How can we create a database using PHP and mysql?&lt;br /&gt;We can create MySQL database with the use of mysql_create_db($databaseName) to create a database.&lt;br /&gt;&lt;br /&gt;How many ways we can retrieve the date in result set of mysql using php?&lt;br /&gt;As individual objects so single record or as a set or arrays.&lt;br /&gt;&lt;br /&gt;Can we use include ("abc.php") two times in a php page "makeit.php"?&lt;br /&gt;Yes.&lt;br /&gt;&lt;br /&gt;For printing out strings, there are echo, print and printf. Explain the differences.&lt;br /&gt;echo is the most primitive of them, and just outputs the contents following the construct to the screen. print is also a construct (so parentheses are optional when calling it), but it returns TRUE on successful output and FALSE if it was unable to print out the string. However, you can pass multiple parameters to echo, like:&lt;br /&gt;&lt;br /&gt;&lt;?php echo 'Welcome ', 'to', ' ', 'fyicenter!'; ?&gt;&lt;br /&gt;&lt;br /&gt;and it will output the string "Welcome to fyicenter!" print does not take multiple parameters. It is also generally argued that echo is faster, but usually the speed advantage is negligible, and might not be there for future versions of PHP. printf is a function, not a construct, and allows such advantages as formatted output, but it’s the slowest way to print out data out of echo, print and printf.&lt;br /&gt;&lt;br /&gt;I am writing an application in PHP that outputs a printable version of driving directions. It contains some long sentences, and I am a neat freak, and would like to make sure that no line exceeds 50 characters. How do I accomplish that with PHP?&lt;br /&gt;On large strings that need to be formatted according to some length specifications, use wordwrap() or chunk_split().&lt;br /&gt;&lt;br /&gt;What’s the output of the ucwords function in this example?&lt;br /&gt;$formatted = ucwords("FYICENTER IS COLLECTION OF INTERVIEW QUESTIONS");&lt;br /&gt;print $formatted;&lt;br /&gt;What will be printed is FYICENTER IS COLLECTION OF INTERVIEW QUESTIONS.&lt;br /&gt;ucwords() makes every first letter of every word capital, but it does not lower-case anything else. To avoid this, and get a properly formatted string, it’s worth using strtolower() first.&lt;br /&gt;&lt;br /&gt;What’s the difference between htmlentities() and htmlspecialchars()?&lt;br /&gt;htmlspecialchars only takes care of &lt;, &gt;, single quote ‘, double quote " and ampersand. htmlentities translates all occurrences of character sequences that have different meaning in HTML.&lt;br /&gt;&lt;br /&gt;How can we extract string "abc.com" from a string "mailto:info@abc.com?subject=Feedback" using regular expression of PHP?&lt;br /&gt;$text = "mailto:info@abc.com?subject=Feedback";&lt;br /&gt;preg_match('|.*@([^?]*)|', $text, $output);&lt;br /&gt;echo $output[1];&lt;br /&gt;&lt;br /&gt;Note that the second index of $output, $output[1], gives the match, not the first one, $output[0].&lt;br /&gt;&lt;br /&gt;So if md5() generates the most secure hash, why would you ever use the less secure crc32() and sha1()?&lt;br /&gt;Crypto usage in PHP is simple, but that doesn’t mean it’s free. First off, depending on the data that you’re encrypting, you might have reasons to store a 32-bit value in the database instead of the 160-bit value to save on space. Second, the more secure the crypto is, the longer is the computation time to deliver the hash value. A high volume site might be significantly slowed down, if frequent md5() generation is required.&lt;br /&gt;&lt;br /&gt;How can we destroy the session, how can we unset the variable of a session?&lt;br /&gt;session_unregister() - Unregister a global variable from the current session&lt;br /&gt;session_unset() - Free all session variables&lt;br /&gt;&lt;br /&gt;What are the different functions in sorting an array?&lt;br /&gt;Sorting functions in PHP:&lt;br /&gt;asort()&lt;br /&gt;arsort()&lt;br /&gt;ksort()&lt;br /&gt;krsort()&lt;br /&gt;uksort()&lt;br /&gt;sort()&lt;br /&gt;natsort()&lt;br /&gt;rsort()&lt;br /&gt;&lt;br /&gt;How can we know the count/number of elements of an array?&lt;br /&gt;2 ways:&lt;br /&gt;a) sizeof($array) - This function is an alias of count()&lt;br /&gt;b) count($urarray) - This function returns the number of elements in an array.&lt;br /&gt;Interestingly if you just pass a simple var instead of an array, count() will return 1.&lt;br /&gt;&lt;br /&gt;How many ways we can pass the variable through the navigation between the pages?&lt;br /&gt;At least 3 ways:&lt;br /&gt;&lt;br /&gt;1. Put the variable into session in the first page, and get it back from session in the next page.&lt;br /&gt;2. Put the variable into cookie in the first page, and get it back from the cookie in the next page.&lt;br /&gt;3. Put the variable into a hidden form field, and get it back from the form in the next page.&lt;br /&gt;&lt;br /&gt;What is the maximum length of a table name, a database name, or a field name in MySQL?&lt;br /&gt;Database name: 64 characters&lt;br /&gt;Table name: 64 characters&lt;br /&gt;Column name: 64 characters&lt;br /&gt;&lt;br /&gt;How many values can the SET function of MySQL take?&lt;br /&gt;MySQL SET function can take zero or more values, but at the maximum it can take 64 values.&lt;br /&gt;&lt;br /&gt;What are the other commands to know the structure of a table using MySQL commands except EXPLAIN command?&lt;br /&gt;DESCRIBE table_name;&lt;br /&gt;&lt;br /&gt;How can we find the number of rows in a table using MySQL?&lt;br /&gt;Use this for MySQL&lt;br /&gt;&lt;br /&gt;SELECT COUNT(*) FROM table_name;&lt;br /&gt;&lt;br /&gt;What’s the difference between md5(), crc32() and sha1() crypto on PHP?&lt;br /&gt;The major difference is the length of the hash generated. CRC32 is, evidently, 32 bits, while sha1() returns a 128 bit value, and md5() returns a 160 bit value. This is important when avoiding collisions.&lt;br /&gt;&lt;br /&gt;How can we find the number of rows in a result set using PHP?&lt;br /&gt;Here is how can you find the number of rows in a result set in PHP:&lt;br /&gt;&lt;br /&gt;$result = mysql_query($any_valid_sql, $database_link);&lt;br /&gt;$num_rows = mysql_num_rows($result);&lt;br /&gt;echo "$num_rows rows found";&lt;br /&gt;&lt;br /&gt;How many ways we can we find the current date using MySQL?&lt;br /&gt;SELECT CURDATE();&lt;br /&gt;SELECT CURRENT_DATE();&lt;br /&gt;SELECT CURTIME();&lt;br /&gt;SELECT CURRENT_TIME();&lt;br /&gt;&lt;br /&gt;Give the syntax of GRANT commands?&lt;br /&gt;The generic syntax for GRANT is as following&lt;br /&gt;&lt;br /&gt;GRANT [rights] on [database] TO [username@hostname] IDENTIFIED BY [password]&lt;br /&gt;&lt;br /&gt;Now rights can be:&lt;br /&gt;a) ALL privilages&lt;br /&gt;b) Combination of CREATE, DROP, SELECT, INSERT, UPDATE and DELETE etc.&lt;br /&gt;&lt;br /&gt;We can grant rights on all databse by usingh *.* or some specific database by database.* or a specific table by database.table_name.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Give the syntax of REVOKE commands?&lt;br /&gt;The generic syntax for revoke is as following&lt;br /&gt;&lt;br /&gt;REVOKE [rights] on [database] FROM [username@hostname]&lt;br /&gt;&lt;br /&gt;Now rights can be:&lt;br /&gt;a) ALL privilages&lt;br /&gt;b) Combination of CREATE, DROP, SELECT, INSERT, UPDATE and DELETE etc.&lt;br /&gt;&lt;br /&gt;We can grant rights on all databse by usingh *.* or some specific database by database.* or a specific table by database.table_name.&lt;br /&gt;&lt;br /&gt;Answer the questions with the following assumption&lt;br /&gt;The structure of table view buyers is as follows:&lt;br /&gt;+-------------+-------------+------+-----+---------+----------------+&lt;br /&gt;| Field       | Type        | Null | Key | Default | Extra          |&lt;br /&gt;+-------------+-------------+------+-----+---------+----------------+&lt;br /&gt;| user_pri_id | int(15)     |      | PRI | NULL    | auto_increment |&lt;br /&gt;| userid      | varchar(10) | YES  |     | NULL    |                |&lt;br /&gt;+-------------+-------------+------+-----+---------+----------------+&lt;br /&gt;The value of user_pri_id of the last row is 2345. What will happen in the following conditions?&lt;br /&gt;Condition 1: Delete all the rows and insert another row. What is the starting value for this auto incremented field user_pri_id?&lt;br /&gt;Condition 2: Delete the last row (having the field value 2345) and insert another row. What is the value for this auto incremented field user_pri_id?&lt;br /&gt;In both conditions, the value of this auto incremented field user_pri_id is 2346.&lt;br /&gt;&lt;br /&gt;What is the difference between CHAR and VARCHAR data types?&lt;br /&gt;CHAR is a fixed length data type. CHAR(n) will take n characters of storage even if you enter less than n characters to that column. For example, "Hello!" will be stored as "Hello! " in CHAR(10) column.&lt;br /&gt;VARCHAR is a variable length data type. VARCHAR(n) will take only the required storage for the actual number of characters entered to that column. For example, "Hello!" will be stored as "Hello!" in VARCHAR(10) column.&lt;br /&gt;How can we encrypt and decrypt a data present in a mysql table using mysql?&lt;br /&gt;AES_ENCRYPT() and AES_DECRYPT()&lt;br /&gt;&lt;br /&gt;Will comparison of string "10" and integer 11 work in PHP?&lt;br /&gt;Yes, internally PHP will cast everything to the integer type, so numbers 10 and 11 will be compared.&lt;br /&gt;&lt;br /&gt;What is the functionality of MD5 function in PHP?&lt;br /&gt;string md5(string)&lt;br /&gt;&lt;br /&gt;It calculates the MD5 hash of a string. The hash is a 32-character hexadecimal number.&lt;br /&gt;&lt;br /&gt;How can I load data from a text file into a table?&lt;br /&gt;The MySQL provides a LOAD DATA INFILE command. You can load data from a file. Great tool but you need to make sure that:&lt;br /&gt;&lt;br /&gt;a) Data must be delimited&lt;br /&gt;b) Data fields must match table columns correctly&lt;br /&gt;&lt;br /&gt;How can we know the number of days between two given dates using MySQL?&lt;br /&gt;Use DATEDIFF()&lt;br /&gt;&lt;br /&gt;SELECT DATEDIFF(NOW(),'2006-07-01');&lt;br /&gt;&lt;br /&gt;How can we change the name of a column of a table?&lt;br /&gt;This will change the name of column:&lt;br /&gt;&lt;br /&gt;ALTER TABLE table_name CHANGE old_colm_name new_colm_name&lt;br /&gt;&lt;br /&gt;How can we change the data type of a column of a table?&lt;br /&gt;This will change the data type of a column:&lt;br /&gt;&lt;br /&gt;ALTER TABLE table_name CHANGE colm_name same_colm_name [new data type]&lt;br /&gt;&lt;br /&gt;What is the difference between GROUP BY and ORDER BY in SQL?&lt;br /&gt;To sort a result, use an ORDER BY clause.&lt;br /&gt;The most general way to satisfy a GROUP BY clause is to scan the whole table and create a new temporary table where all rows from each group are consecutive, and then use this temporary table to discover groups and apply aggregate functions (if any).&lt;br /&gt;ORDER BY [col1],[col2],...[coln]; Tells DBMS according to what columns it should sort the result. If two rows will hawe the same value in col1 it will try to sort them according to col2 and so on.&lt;br /&gt;GROUP BY [col1],[col2],...[coln]; Tells DBMS to group (aggregate) results with same value of column col1. You can use COUNT(col1), SUM(col1), AVG(col1) with it, if you want to count all items in group, sum all values or view average.&lt;br /&gt;&lt;br /&gt;What is meant by MIME?&lt;br /&gt;Answer 1:&lt;br /&gt;MIME is Multipurpose Internet Mail Extensions is an Internet standard for the format of e-mail. However browsers also uses MIME standard to transmit files. MIME has a header which is added to a beginning of the data. When browser sees such header it shows the data as it would be a file (for example image)&lt;br /&gt;&lt;br /&gt;Some examples of MIME types:&lt;br /&gt;audio/x-ms-wmp&lt;br /&gt;image/png&lt;br /&gt;aplication/x-shockwave-flash&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Answer 2:&lt;br /&gt;Multipurpose Internet Mail Extensions.&lt;br /&gt;WWW's ability to recognize and handle files of different types is largely dependent on the use of the MIME (Multipurpose Internet Mail Extensions) standard. The standard provides for a system of registration of file types with information about the applications needed to process them. This information is incorporated into Web server and browser software, and enables the automatic recognition and display of registered file types. …&lt;br /&gt;&lt;br /&gt;How can we know that a session is started or not?&lt;br /&gt;A session starts by session_start() function.&lt;br /&gt;This session_start() is always declared in header portion. it always declares first. then we write session_register().&lt;br /&gt;&lt;br /&gt;What are the differences between mysql_fetch_array(), mysql_fetch_object(), mysql_fetch_row()?&lt;br /&gt;Answer 1:&lt;br /&gt;mysql_fetch_array() -&gt; Fetch a result row as a combination of associative array and regular array.&lt;br /&gt;mysql_fetch_object() -&gt; Fetch a result row as an object.&lt;br /&gt;mysql_fetch_row() -&gt; Fetch a result set as a regular array().&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Answer 2:&lt;br /&gt;The difference between mysql_fetch_row() and mysql_fetch_array() is that the first returns the results in a numeric array ($row[0], $row[1], etc.), while the latter returns a the results an array containing both numeric and associative keys ($row['name'], $row['email'], etc.). mysql_fetch_object() returns an object ($row-&gt;name, $row-&gt;email, etc.).&lt;br /&gt;&lt;br /&gt;If we login more than one browser windows at the same time with same user and after that we close one window, then is the session is exist to other windows or not? And if yes then why? If no then why?&lt;br /&gt;Session depends on browser. If browser is closed then session is lost. The session data will be deleted after session time out. If connection is lost and you recreate connection, then session will continue in the browser.&lt;br /&gt;&lt;br /&gt;What are the MySQL database files stored in system ?&lt;br /&gt;Data is stored in name.myd&lt;br /&gt;Table structure is stored in name.frm&lt;br /&gt;Index is stored in name.myi&lt;br /&gt;&lt;br /&gt;What is the difference between PHP4 and PHP5?&lt;br /&gt;PHP4 cannot support oops concepts and Zend engine 1 is used.&lt;br /&gt;&lt;br /&gt;PHP5 supports oops concepts and Zend engine 2 is used.&lt;br /&gt;Error supporting is increased in PHP5.&lt;br /&gt;XML and SQLLite will is increased in PHP5.&lt;br /&gt;&lt;br /&gt;Can we use include(abc.PHP) two times in a PHP page makeit.PHP”?&lt;br /&gt;Yes we can include that many times we want, but here are some things to make sure of:&lt;br /&gt;(including abc.PHP, the file names are case-sensitive)&lt;br /&gt;there shouldn't be any duplicate function names, means there should not be functions or classes or variables with the same name in abc.PHP and makeit.php&lt;br /&gt;&lt;br /&gt;What are the differences between mysql_fetch_array(), mysql_fetch_object(), mysql_fetch_row()?&lt;br /&gt;mysql_fetch_array - Fetch a result row as an associative array and a numeric array.&lt;br /&gt;&lt;br /&gt;mysql_fetch_object - Returns an object with properties that correspond to the fetched row and moves the internal data pointer ahead. Returns an object with properties that correspond to the fetched row, or FALSE if there are no more rows&lt;br /&gt;&lt;br /&gt;mysql_fetch_row() - Fetches one row of data from the result associated with the specified result identifier. The row is returned as an array. Each result column is stored in an array offset, starting at offset 0.&lt;br /&gt;&lt;br /&gt;What is meant by nl2br()?&lt;br /&gt;Anwser1:&lt;br /&gt;nl2br() inserts a HTML tag &lt;br /&gt; before all new line characters \n in a string.&lt;br /&gt;&lt;br /&gt;echo nl2br("god bless \n you");&lt;br /&gt;&lt;br /&gt;output:&lt;br /&gt;god bless&lt;br /&gt;&lt;br /&gt;you&lt;br /&gt;&lt;br /&gt;How can we encrypt and decrypt a data presented in a table using MySQL?&lt;br /&gt;You can use functions: AES_ENCRYPT() and AES_DECRYPT() like:&lt;br /&gt;&lt;br /&gt;AES_ENCRYPT(str, key_str)&lt;br /&gt;AES_DECRYPT(crypt_str, key_str)&lt;br /&gt;&lt;br /&gt;How can I retrieve values from one database server and store them in other database server using PHP?&lt;br /&gt;For this purpose, you can first read the data from one server into session variables. Then connect to other server and simply insert the data into the database.&lt;br /&gt;&lt;br /&gt;WHO IS THE FATHER OF PHP AND WHAT IS THE CURRENT VERSION OF PHP AND MYSQL?&lt;br /&gt;Rasmus Lerdorf.&lt;br /&gt;PHP 5.1. Beta&lt;br /&gt;MySQL 5.0&lt;br /&gt;&lt;br /&gt;IN HOW MANY WAYS WE CAN RETRIEVE DATA IN THE RESULT SET OF MYSQL USING PHP?&lt;br /&gt;mysql_fetch_array - Fetch a result row as an associative array, a numeric array, or both&lt;br /&gt;mysql_fetch_assoc - Fetch a result row as an associative array&lt;br /&gt;mysql_fetch_object - Fetch a result row as an object&lt;br /&gt;mysql_fetch_row —- Get a result row as an enumerated array&lt;br /&gt;&lt;br /&gt;What are the functions for IMAP?&lt;br /&gt;imap_body - Read the message body&lt;br /&gt;imap_check - Check current mailbox&lt;br /&gt;imap_delete - Mark a message for deletion from current mailbox&lt;br /&gt;imap_mail - Send an email message&lt;br /&gt;&lt;br /&gt;What are encryption functions in PHP?&lt;br /&gt;CRYPT()&lt;br /&gt;MD5()&lt;br /&gt;&lt;br /&gt;What is the difference between htmlentities() and htmlspecialchars()?&lt;br /&gt;htmlspecialchars() - Convert some special characters to HTML entities (Only the most widely used)&lt;br /&gt;htmlentities() - Convert ALL special characters to HTML entities&lt;br /&gt;&lt;br /&gt;What is the functionality of the function htmlentities?&lt;br /&gt;htmlentities() - Convert all applicable characters to HTML entities&lt;br /&gt;This function is identical to htmlspecialchars() in all ways, except with htmlentities(), all characters which have HTML character entity equivalents are translated into these entities.&lt;br /&gt;&lt;br /&gt;How can we get the properties (size, type, width, height) of an image using php image functions?&lt;br /&gt;To know the image size use getimagesize() function&lt;br /&gt;To know the image width use imagesx() function&lt;br /&gt;To know the image height use imagesy() function&lt;br /&gt;&lt;br /&gt;How can we increase the execution time of a php script?&lt;br /&gt;By the use of void set_time_limit(int seconds)&lt;br /&gt;Set the number of seconds a script is allowed to run. If this is reached, the script returns a fatal error. The default limit is 30 seconds or, if it exists, the max_execution_time value defined in the php.ini. If seconds is set to zero, no time limit is imposed.&lt;br /&gt;&lt;br /&gt;When called, set_time_limit() restarts the timeout counter from zero. In other words, if the timeout is the default 30 seconds, and 25 seconds into script execution a call such as set_time_limit(20) is made, the script will run for a total of 45 seconds before timing out.&lt;br /&gt;&lt;br /&gt;HOW CAN WE TAKE A BACKUP OF A MYSQL TABLE AND HOW CAN WE RESTORE IT?&lt;br /&gt;Answer 1:&lt;br /&gt;Create a full backup of your database: shell&gt; mysqldump tab=/path/to/some/dir opt db_name&lt;br /&gt;Or: shell&gt; mysqlhotcopy db_name /path/to/some/dir&lt;br /&gt;&lt;br /&gt;The full backup file is just a set of SQL statements, so restoring it is very easy:&lt;br /&gt;&lt;br /&gt;shell&gt; mysql "."Executed";&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Answer 2:&lt;br /&gt;To backup: BACKUP TABLE tbl_name TO /path/to/backup/directory&lt;br /&gt;’ To restore: RESTORE TABLE tbl_name FROM /path/to/backup/directory&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;mysqldump: Dumping Table Structure and Data&lt;br /&gt;&lt;br /&gt;Utility to dump a database or a collection of database for backup or for transferring the data to another SQL server (not necessarily a MySQL server). The dump will contain SQL statements to create the table and/or populate the table.&lt;br /&gt;-t, no-create-info&lt;br /&gt;Don't write table creation information (the CREATE TABLE statement).&lt;br /&gt;-d, no-data&lt;br /&gt;Don't write any row information for the table. This is very useful if you just want to get a dump of the structure for a table!&lt;br /&gt;&lt;br /&gt;How to set cookies?&lt;br /&gt;setcookie('variable','value','time')&lt;br /&gt;;&lt;br /&gt;variable - name of the cookie variable&lt;br /&gt;value - value of the cookie variable&lt;br /&gt;time - expiry time&lt;br /&gt;Example: setcookie('Test',$i,time()+3600);&lt;br /&gt;&lt;br /&gt;Test - cookie variable name&lt;br /&gt;$i - value of the variable 'Test'&lt;br /&gt;time()+3600 - denotes that the cookie will expire after an one hour&lt;br /&gt;&lt;br /&gt;How to reset/destroy a cookie&lt;br /&gt;Reset a cookie by specifying expire time in the past:&lt;br /&gt;Example: setcookie('Test',$i,time()-3600); // already expired time&lt;br /&gt;&lt;br /&gt;Reset a cookie by specifying its name only&lt;br /&gt;Example: setcookie('Test');&lt;br /&gt;&lt;br /&gt;WHAT TYPES OF IMAGES THAT PHP SUPPORTS?&lt;br /&gt;Using imagetypes() function to find out what types of images are supported in your PHP engine.&lt;br /&gt;imagetypes() - Returns the image types supported.&lt;br /&gt;This function returns a bit-field corresponding to the image formats supported by the version of GD linked into PHP. The following bits are returned, IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP | IMG_XPM.&lt;br /&gt;&lt;br /&gt;CHECK IF A VARIABLE IS AN INTEGER IN JAVASCRIPT&lt;br /&gt;var myValue =9.8;&lt;br /&gt;if(parseInt(myValue)== myValue)&lt;br /&gt;alert('Integer');&lt;br /&gt;else&lt;br /&gt;alert('Not an integer');&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Tools used for drawing ER diagrams.&lt;br /&gt;Case Studio&lt;br /&gt;Smart Draw&lt;br /&gt;&lt;br /&gt;How can I know that a variable is a number or not using a JavaScript?&lt;br /&gt;Answer 1:&lt;br /&gt;bool is_numeric( mixed var)&lt;br /&gt;Returns TRUE if var is a number or a numeric string, FALSE otherwise.&lt;br /&gt;&lt;br /&gt;Answer 2:&lt;br /&gt;Definition and Usage&lt;br /&gt;The isNaN() function is used to check if a value is not a number.&lt;br /&gt;&lt;br /&gt;Syntax&lt;br /&gt;isNaN(number)&lt;br /&gt;&lt;br /&gt;Parameter Description&lt;br /&gt;number Required. The value to be tested&lt;br /&gt;&lt;br /&gt;How can we submit from without a submit button?&lt;br /&gt;Trigger the JavaScript code on any event ( like onSelect of drop down list box, onfocus, etc ) document.myform.submit(); This will submit the form.&lt;br /&gt;&lt;br /&gt;How many ways can we get the value of current session id?&lt;br /&gt;session_id() returns the session id for the current session.&lt;br /&gt;&lt;br /&gt;How can we destroy the cookie?&lt;br /&gt;Set the cookie with a past expiration time.&lt;br /&gt;&lt;br /&gt;What are the current versions of Apache, PHP, and MySQL?&lt;br /&gt;PHP: PHP 5.1.2&lt;br /&gt;MySQL: MySQL 5.1&lt;br /&gt;Apache: Apache 2.1&lt;br /&gt;&lt;br /&gt;What are the reasons for selecting LAMP (Linux, Apache, MySQL, Php) instead of combination of other software programs, servers and operating systems?&lt;br /&gt;All of those are open source resource. Security of linux is very very more than windows. Apache is a better server that IIS both in functionality and security. Mysql is world most popular open source database. Php is more faster that asp or any other scripting language.&lt;br /&gt;&lt;br /&gt;What are the features and advantages of OBJECT ORIENTED PROGRAMMING?&lt;br /&gt;One of the main advantages of OO programming is its ease of modification; objects can easily be modified and added to a system there by reducing maintenance costs. OO programming is also considered to be better at modeling the real world than is procedural programming. It allows for more complicated and flexible interactions. OO systems are also easier for non-technical personnel to understand and easier for them to participate in the maintenance and enhancement of a system because it appeals to natural human cognition patterns. For some systems, an OO approach can speed development time since many objects are standard across systems and can be reused. Components that manage dates, shipping, shopping carts, etc. can be purchased and easily modified for a specific system.&lt;br /&gt;&lt;br /&gt;What is the use of friend function?&lt;br /&gt;Friend functions&lt;br /&gt;Sometimes a function is best shared among a number of different classes. Such functions can be declared either as member functions of one class or as global functions. In either case they can be set to be friends of other classes, by using a friend specifier in the class that is admitting them. Such functions can use all attributes of the class which names them as a friend, as if they were themselves members of that class.&lt;br /&gt;A friend declaration is essentially a prototype for a member function, but instead of requiring an implementation with the name of that class attached by the double colon syntax, a global function or member function of another class provides the match.&lt;br /&gt;class mylinkage&lt;br /&gt;{&lt;br /&gt;private:&lt;br /&gt;mylinkage * prev;&lt;br /&gt;mylinkage * next;&lt;br /&gt;&lt;br /&gt;protected:&lt;br /&gt;friend void set_prev(mylinkage* L, mylinkage* N);&lt;br /&gt;void set_next(mylinkage* L);&lt;br /&gt;&lt;br /&gt;public:&lt;br /&gt;mylinkage * succ();&lt;br /&gt;mylinkage * pred();&lt;br /&gt;mylinkage();&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;void mylinkage::set_next(mylinkage* L) { next = L; }&lt;br /&gt;&lt;br /&gt;void set_prev(mylinkage * L, mylinkage * N ) { N-&gt;prev = L; }&lt;br /&gt;&lt;br /&gt;Friends in other classes&lt;br /&gt;It is possible to specify a member function of another class as a friend as follows:&lt;br /&gt;class C&lt;br /&gt;{&lt;br /&gt;friend int B::f1();&lt;br /&gt;};&lt;br /&gt;class B&lt;br /&gt;{&lt;br /&gt;int f1();&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;It is also possible to specify all the functions in another class as friends, by specifying the entire class as a friend.&lt;br /&gt;class A&lt;br /&gt;{&lt;br /&gt;friend class B;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;Friend functions allow binary operators to be defined which combine private data in a pair of objects. This is particularly powerful when using the operator overloading features of C++. We will return to it when we look at overloading.&lt;br /&gt;&lt;br /&gt;How can we get second of the current time using date function?&lt;br /&gt;$second = date("s");&lt;br /&gt;&lt;br /&gt;What is the maximum size of a file that can be uploaded using PHP and how can we change this?&lt;br /&gt;You can change maximum size of a file set upload_max_filesize variable in php.ini file&lt;br /&gt;&lt;br /&gt;How can I make a script that can be bilingual (supports English, German)?&lt;br /&gt;You can change charset variable in above line in the script to support bilanguage.&lt;br /&gt;&lt;br /&gt;What are the difference between abstract class and interface?&lt;br /&gt;Abstract class: abstract classes are the class where one or more methods are abstract but not necessarily all method has to be abstract. Abstract methods are the methods, which are declare in its class but not define. The definition of those methods must be in its extending class.&lt;br /&gt;&lt;br /&gt;Interface: Interfaces are one type of class where all the methods are abstract. That means all the methods only declared but not defined. All the methods must be define by its implemented class.&lt;br /&gt;&lt;br /&gt;What are the advantages of stored procedures, triggers, indexes?&lt;br /&gt;A stored procedure is a set of SQL commands that can be compiled and stored in the server. Once this has been done, clients don't need to keep re-issuing the entire query but can refer to the stored procedure. This provides better overall performance because the query has to be parsed only once, and less information needs to be sent between the server and the client. You can also raise the conceptual level by having libraries of functions in the server. However, stored procedures of course do increase the load on the database server system, as more of the work is done on the server side and less on the client (application) side. Triggers will also be implemented. A trigger is effectively a type of stored procedure, one that is invoked when a particular event occurs. For example, you can install a stored procedure that is triggered each time a record is deleted from a transaction table and that stored procedure automatically deletes the corresponding customer from a customer table when all his transactions are deleted. Indexes are used to find rows with specific column values quickly. Without an index, MySQL must begin with the first row and then read through the entire table to find the relevant rows. The larger the table, the more this costs. If the table has an index for the columns in question, MySQL can quickly determine the position to seek to in the middle of the data file without having to look at all the data. If a table has 1,000 rows, this is at least 100 times faster than reading sequentially. If you need to access most of the rows, it is faster to read sequentially, because this minimizes disk seeks.&lt;br /&gt;&lt;br /&gt;What is maximum size of a database in mysql?&lt;br /&gt;If the operating system or filesystem places a limit on the number of files in a directory, MySQL is bound by that constraint. The efficiency of the operating system in handling large numbers of files in a directory can place a practical limit on the number of tables in a database. If the time required to open a file in the directory increases significantly as the number of files increases, database performance can be adversely affected.&lt;br /&gt;The amount of available disk space limits the number of tables.&lt;br /&gt;MySQL 3.22 had a 4GB (4 gigabyte) limit on table size. With the MyISAM storage engine in MySQL 3.23, the maximum table size was increased to 65536 terabytes (2567 – 1 bytes). With this larger allowed table size, the maximum effective table size for MySQL databases is usually determined by operating system constraints on file sizes, not by MySQL internal limits.&lt;br /&gt;The InnoDB storage engine maintains InnoDB tables within a tablespace that can be created from several files. This allows a table to exceed the maximum individual file size. The tablespace can include raw disk partitions, which allows extremely large tables. The maximum tablespace size is 64TB.&lt;br /&gt;The following table lists some examples of operating system file-size limits. This is only a rough guide and is not intended to be definitive. For the most up-to-date information, be sure to check the documentation specific to your operating system.&lt;br /&gt;Operating System File-size Limit&lt;br /&gt;Linux 2.2-Intel 32-bit 2GB (LFS: 4GB)&lt;br /&gt;Linux 2.4+ (using ext3 filesystem) 4TB&lt;br /&gt;Solaris 9/10 16TB&lt;br /&gt;NetWare w/NSS filesystem 8TB&lt;br /&gt;Win32 w/ FAT/FAT32 2GB/4GB&lt;br /&gt;Win32 w/ NTFS 2TB (possibly larger)&lt;br /&gt;MacOS X w/ HFS+ 2TB&lt;br /&gt;&lt;br /&gt;Explain normalization concept?&lt;br /&gt;The normalization process involves getting our data to conform to three progressive normal forms, and a higher level of normalization cannot be achieved until the previous levels have been achieved (there are actually five normal forms, but the last two are mainly academic and will not be discussed).&lt;br /&gt;&lt;br /&gt;First Normal Form&lt;br /&gt;The First Normal Form (or 1NF) involves removal of redundant data from horizontal rows. We want to ensure that there is no duplication of data in a given row, and that every column stores the least amount of information possible (making the field atomic).&lt;br /&gt;&lt;br /&gt;Second Normal Form&lt;br /&gt;Where the First Normal Form deals with redundancy of data across a horizontal row, Second Normal Form (or 2NF) deals with redundancy of data in vertical columns. As stated earlier, the normal forms are progressive, so to achieve Second Normal Form, your tables must already be in First Normal Form.&lt;br /&gt;&lt;br /&gt;Third Normal Form&lt;br /&gt;I have a confession to make; I do not often use Third Normal Form. In Third Normal Form we are looking for data in our tables that is not fully dependant on the primary key, but dependant on another value in the table&lt;br /&gt;&lt;br /&gt;What’s the difference between accessing a class method via -&gt; and via ::?&lt;br /&gt;:: is allowed to access methods that can perform static operations, i.e. those, which do not require object initialization.&lt;br /&gt;&lt;br /&gt;What are the advantages and disadvantages of CASCADE STYLE SHEETS?&lt;br /&gt;External Style Sheets&lt;br /&gt;Advantages&lt;br /&gt;Can control styles for multiple documents at once Classes can be created for use on multiple HTML element types in many documents Selector and grouping methods can be used to apply styles under complex contexts&lt;br /&gt;&lt;br /&gt;Disadvantages&lt;br /&gt;An extra download is required to import style information for each document The rendering of the document may be delayed until the external style sheet is loaded Becomes slightly unwieldy for small quantities of style definitions&lt;br /&gt;&lt;br /&gt;Embedded Style Sheets&lt;br /&gt;Advantages&lt;br /&gt;Classes can be created for use on multiple tag types in the document Selector and grouping methods can be used to apply styles under complex contexts No additional downloads necessary to receive style information&lt;br /&gt;&lt;br /&gt;Disadvantage&lt;br /&gt;This method can not control styles for multiple documents at once&lt;br /&gt;&lt;br /&gt;Inline Styles&lt;br /&gt;Advantages&lt;br /&gt;Useful for small quantities of style definitions Can override other style specification methods at the local level so only exceptions need to be listed in conjunction with other style methods&lt;br /&gt;&lt;br /&gt;Disadvantages&lt;br /&gt;Does not distance style information from content (a main goal of SGML/HTML) Can not control styles for multiple documents at once Author can not create or control classes of elements to control multiple element types within the document Selector grouping methods can not be used to create complex element addressing scenarios&lt;br /&gt;&lt;br /&gt;What type of inheritance that php supports?&lt;br /&gt;In PHP an extended class is always dependent on a single base class, that is, multiple inheritance is not supported. Classes are extended using the keyword 'extends'.&lt;br /&gt;&lt;br /&gt;How can increase the performance of MySQL select query?&lt;br /&gt;We can use LIMIT to stop MySql for further search in table after we have received our required no. of records, also we can use LEFT JOIN or RIGHT JOIN instead of full join in cases we have related data in two or more tables.&lt;br /&gt;&lt;br /&gt;How can we change the name of a column of a table?&lt;br /&gt;MySQL query to rename table: RENAME TABLE tbl_name TO new_tbl_name&lt;br /&gt;or,&lt;br /&gt;ALTER TABLE tableName CHANGE OldName newName.&lt;br /&gt;&lt;br /&gt;When you want to show some part of a text displayed on an HTML page in red font color? What different possibilities are there to do this? What are the advantages/disadvantages of these methods?&lt;br /&gt;There are 2 ways to show some part of a text in red:&lt;br /&gt;&lt;br /&gt;1. Using HTML tag &lt;span style="color:red;"&gt;&lt;br /&gt;2. Using HTML tag &lt;span style="color: red"&gt;&lt;br /&gt;&lt;br /&gt;When viewing an HTML page in a Browser, the Browser often keeps this page in its cache. What can be possible advantages/disadvantages of page caching? How can you prevent caching of a certain page (please give several alternate solutions)?&lt;br /&gt;When you use the metatag in the header section at the beginning of an HTML Web page, the Web page may still be cached in the Temporary Internet Files folder.&lt;br /&gt;&lt;br /&gt;A page that Internet Explorer is browsing is not cached until half of the 64 KB buffer is filled. Usually, metatags are inserted in the header section of an HTML document, which appears at the beginning of the document. When the HTML code is parsed, it is read from top to bottom. When the metatag is read, Internet Explorer looks for the existence of the page in cache at that exact moment. If it is there, it is removed. To properly prevent the Web page from appearing in the cache, place another header section at the end of the HTML document. For example:&lt;br /&gt;&lt;br /&gt;What are the different ways to login to a remote server? Explain the means, advantages and disadvantages?&lt;br /&gt;There is at least 3 ways to logon to a remote server:&lt;br /&gt;Use ssh or telnet if you concern with security&lt;br /&gt;You can also use rlogin to logon to a remote server.&lt;br /&gt;&lt;br /&gt;Please give a regular expression (preferably Perl/PREG style), which can be used to identify the URL from within a HTML link tag.&lt;br /&gt;Try this: /href="([^"]*)"/i&lt;br /&gt;&lt;br /&gt;How can I use the COM components in php?&lt;br /&gt;The COM class provides a framework to integrate (D)COM components into your PHP scripts.&lt;br /&gt;string COM::COM( string module_name [, string server_name [, int codepage]]) - COM class constructor.&lt;br /&gt;&lt;br /&gt;Parameters:&lt;br /&gt;&lt;br /&gt;module_name: name or class-id of the requested component.&lt;br /&gt;server_name: name of the DCOM server from which the component should be fetched. If NULL, localhost is assumed. To allow DCOM com, allow_dcom has to be set to TRUE in php.ini.&lt;br /&gt;codepage - specifies the codepage that is used to convert php-strings to unicode-strings and vice versa. Possible values are CP_ACP, CP_MACCP, CP_OEMCP, CP_SYMBOL, CP_THREAD_ACP, CP_UTF7 and CP_UTF8.&lt;br /&gt;Usage:&lt;br /&gt;$word-&gt;Visible = 1; //open an empty document&lt;br /&gt;$word-&gt;Documents-&gt;Add(); //do some weird stuff&lt;br /&gt;$word-&gt;Selection-&gt;TypeText("This is a test…");&lt;br /&gt;$word-&gt;Documents[1]-&gt;SaveAs("Useless test.doc"); //closing word&lt;br /&gt;$word-&gt;Quit(); //free the object&lt;br /&gt;$word-&gt;Release();&lt;br /&gt;$word = null;&lt;br /&gt;&lt;br /&gt;How many ways we can give the output to a browser?&lt;br /&gt;HTML output&lt;br /&gt;PHP, ASP, JSP, Servlet Function&lt;br /&gt;Script Language output Function&lt;br /&gt;Different Type of embedded Package to output to a browser&lt;br /&gt;&lt;br /&gt;What is the default session time in php and how can I change it?&lt;br /&gt;The default session time in php is until closing of browser&lt;br /&gt;&lt;br /&gt;What changes I have to do in php.ini file for file uploading?&lt;br /&gt;Make the following line uncomment like:&lt;br /&gt;; Whether to allow HTTP file uploads.&lt;br /&gt;file_uploads = On&lt;br /&gt;; Temporary directory for HTTP uploaded files (will use system default if not&lt;br /&gt;; specified).&lt;br /&gt;upload_tmp_dir = C:\apache2triad\temp&lt;br /&gt;; Maximum allowed size for uploaded files.&lt;br /&gt;upload_max_filesize = 2M&lt;br /&gt;&lt;br /&gt;How can I set a cron and how can I execute it in Unix, Linux, and windows?&lt;br /&gt;Cron is very simply a Linux module that allows you to run commands at predetermined times or intervals. In Windows, it's called Scheduled Tasks. The name Cron is in fact derived from the same word from which we get the word chronology, which means order of time.&lt;br /&gt;The easiest way to use crontab is via the crontab command.&lt;br /&gt;&lt;br /&gt;# crontab&lt;br /&gt;&lt;br /&gt;This command 'edits' the crontab. Upon employing this command, you will be able to enter the commands that you wish to run. My version of&lt;br /&gt;Linux uses the text editor vi. You can find information on using vi here.&lt;br /&gt;&lt;br /&gt;The syntax of this file is very important – if you get it wrong, your crontab will not function properly. The syntax of the file should be as follows:&lt;br /&gt;minutes hours day_of_month month day_of_week command&lt;br /&gt;&lt;br /&gt;All the variables, with the exception of the command itself, are numerical constants. In addition to an asterisk (*), which is a wildcard that allows any value, the ranges permitted for each field are as follows:&lt;br /&gt;&lt;br /&gt;Minutes: 0-59&lt;br /&gt;Hours: 0-23&lt;br /&gt;Day_of_month: 1-31&lt;br /&gt;Month: 1-12&lt;br /&gt;Weekday: 0-6&lt;br /&gt;&lt;br /&gt;We can also include multiple values for each entry, simply by separating each value with a comma.&lt;br /&gt;command can be any shell command and, as we will see momentarily, can also be used to execute a Web document such as a PHP file.&lt;br /&gt;So, if we want to run a script every Tuesday morning at 8:15 AM, our mycronjob file will contain the following content on a single line:&lt;br /&gt;&lt;br /&gt;15 8 * * 2 /path/to/scriptname&lt;br /&gt;&lt;br /&gt;This all seems simple enough, right? Not so fast! If you try to run a PHP script in this manner, nothing will happen (barring very special configurations that have PHP compiled as an executable, as opposed to an Apache module). The reason is that, in order for PHP to be parsed, it needs to be passed through Apache. In other words, the page needs to be called via a browser or other means of retrieving&lt;br /&gt;&lt;br /&gt;Web content. For our purposes, I'll assume that your server configuration includes wget, as is the case with most default configurations. To test your configuration, log in to shell. If you're using an RPM-based system (e.g. Redhat or Mandrake), type the following:&lt;br /&gt;&lt;br /&gt;# wget help&lt;br /&gt;&lt;br /&gt;If you are greeted with a wget package identification, it is installed in your system.&lt;br /&gt;You could execute the PHP by invoking wget on the URL to the page, like so:&lt;br /&gt;&lt;br /&gt;# wget http://www.example.com/file.php&lt;br /&gt;&lt;br /&gt;Now, let's go back to the mailstock.php file we created in the first part of this article. We saved it in our document root, so it should be accessible via the Internet. Remember that we wanted it to run at 4PM Eastern time, and send you your precious closing bell report? Since I'm located in the Eastern timezone, we can go ahead and set up our crontab to use 4:00, but if you live elsewhere, you might have to compensate for the time difference when setting this value.&lt;br /&gt;This is what my crontab will look like:&lt;br /&gt;&lt;br /&gt;0 4 * * 1,2,3,4,5 wget http://www.example.com/mailstock.php&lt;br /&gt;Steps for the payment gateway processing?&lt;br /&gt;An online payment gateway is the interface between your merchant account and your Web site. The online payment gateway allows you to immediately verify credit card transactions and authorize funds on a customer's credit card directly from your Web site. It then passes the transaction off to your merchant bank for processing, commonly referred to as transaction batching&lt;br /&gt;&lt;br /&gt;How many ways I can redirect a PHP page?&lt;br /&gt;Here are the possible ways of php page redirection.&lt;br /&gt;&lt;br /&gt;1. Using Java script:&lt;br /&gt;'; echo 'window.location.href="'.$filename.'";'; echo ''; echo ''; echo ''; echo ''; } } redirect('http://maosjb.com'); ?&gt;&lt;br /&gt;&lt;br /&gt;2. Using php function: header("Location:http://maosjb.com ");&lt;br /&gt;&lt;br /&gt;List out different arguments in PHP header function?&lt;br /&gt;void header ( string string [, bool replace [, int http_response_code]])&lt;br /&gt;&lt;br /&gt;What type of headers have to be added in the mail function to attach a file?&lt;br /&gt;$boundary = '--' . md5( uniqid ( rand() ) );&lt;br /&gt;$headers = "From: \"Me\"\n";&lt;br /&gt;$headers .= "MIME-Version: 1.0\n";&lt;br /&gt;$headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"";&lt;br /&gt;&lt;br /&gt;How to store the uploaded file to the final location?&lt;br /&gt;move_uploaded_file ( string filename, string destination)&lt;br /&gt;&lt;br /&gt;This function checks to ensure that the file designated by filename is a valid upload file (meaning that it was uploaded via PHP's HTTP POST upload mechanism). If the file is valid, it will be moved to the filename given by destination.&lt;br /&gt;&lt;br /&gt;If filename is not a valid upload file, then no action will occur, and move_uploaded_file() will return FALSE.&lt;br /&gt;&lt;br /&gt;If filename is a valid upload file, but cannot be moved for some reason, no action will occur, and move_uploaded_file() will return FALSE. Additionally, a warning will be issued.&lt;br /&gt;&lt;br /&gt;What is the difference between Reply-to and Return-path in the headers of a mail function?&lt;br /&gt;Reply-to: Reply-to is where to delivery the reply of the mail.&lt;br /&gt;&lt;br /&gt;Return-path: Return path is when there is a mail delivery failure occurs then where to delivery the failure notification.&lt;br /&gt;&lt;br /&gt;Explain about Type Juggling in php?&lt;br /&gt;PHP does not require (or support) explicit type definition in variable declaration; a variable's type is determined by the context in which that variable is used. That is to say, if you assign a string value to variable $var, $var becomes a string. If you then assign an integer value to $var, it becomes an integer.&lt;br /&gt;&lt;br /&gt;An example of PHP's automatic type conversion is the addition operator '+'. If any of the operands is a float, then all operands are evaluated as floats, and the result will be a float. Otherwise, the operands will be interpreted as integers, and the result will also be an integer. Note that this does NOT change the types of the operands themselves; the only change is in how the operands are evaluated.&lt;br /&gt;&lt;br /&gt;$foo += 2; // $foo is now an integer (2)&lt;br /&gt;$foo = $foo + 1.3; // $foo is now a float (3.3)&lt;br /&gt;$foo = 5 + "10 Little Piggies"; // $foo is integer (15)&lt;br /&gt;$foo = 5 + "10 Small Pigs"; // $foo is integer (15)&lt;br /&gt;&lt;br /&gt;If the last two examples above seem odd, see String conversion to numbers.&lt;br /&gt;If you wish to change the type of a variable, see settype().&lt;br /&gt;If you would like to test any of the examples in this section, you can use the var_dump() function.&lt;br /&gt;Note: The behavior of an automatic conversion to array is currently undefined.&lt;br /&gt;&lt;br /&gt;Since PHP (for historical reasons) supports indexing into strings via offsets using the same syntax as array indexing, the example above leads to a problem: should $a become an array with its first element being "f", or should "f" become the first character of the string $a? The current versions of PHP interpret the second assignment as a string offset identification, so $a becomes "f", the result of this automatic conversion however should be considered undefined. PHP 4 introduced the new curly bracket syntax to access characters in string, use this syntax instead of the one presented above:&lt;br /&gt;&lt;br /&gt;How can I embed a java programme in php file and what changes have to be done in php.ini file?&lt;br /&gt;There are two possible ways to bridge PHP and Java: you can either integrate PHP into a Java Servlet environment, which is the more stable and efficient solution, or integrate Java support into PHP. The former is provided by a SAPI module that interfaces with the Servlet server, the latter by this Java extension.&lt;br /&gt;The Java extension provides a simple and effective means for creating and invoking methods on Java objects from PHP. The JVM is created using JNI, and everything runs in-process.&lt;br /&gt;&lt;br /&gt;Example Code:&lt;br /&gt;&lt;br /&gt;getProperty('java.version') . ''; echo 'Java vendor=' . $system-&gt;getProperty('java.vendor') . ''; echo 'OS=' . $system-&gt;getProperty('os.name') . ' ' . $system-&gt;getProperty('os.version') . ' on ' . $system-&gt;getProperty('os.arch') . ' '; // java.util.Date example $formatter = new Java('java.text.SimpleDateFormat', "EEEE, MMMM dd, yyyy 'at' h:mm:ss a zzzz"); echo $formatter-&gt;format(new Java('java.util.Date')); ?&gt;&lt;br /&gt;&lt;br /&gt;The behaviour of these functions is affected by settings in php.ini.&lt;br /&gt;Table 1. Java configuration options&lt;br /&gt;Name&lt;br /&gt;Default&lt;br /&gt;Changeable&lt;br /&gt;java.class.path&lt;br /&gt;NULL&lt;br /&gt;PHP_INI_ALL&lt;br /&gt;Name Default Changeable&lt;br /&gt;java.home&lt;br /&gt;NULL&lt;br /&gt;PHP_INI_ALL&lt;br /&gt;java.library.path&lt;br /&gt;NULL&lt;br /&gt;PHP_INI_ALL&lt;br /&gt;java.library&lt;br /&gt;JAVALIB&lt;br /&gt;PHP_INI_ALL&lt;br /&gt;&lt;br /&gt;How To Turn On the Session Support?&lt;br /&gt;The session support can be turned on automatically at the site level, or manually in each PHP page script:&lt;br /&gt; Turning on session support automatically at the site level: Set session.auto_start = 1 in php.ini.&lt;br /&gt; Turning on session support manually in each page script: Call session_start() funtion.&lt;br /&gt;&lt;br /&gt;Explain the ternary conditional operator in PHP?&lt;br /&gt;Expression preceding the ? is evaluated, if it’s true, then the expression preceding the : is executed, otherwise, the expression following : is executed.&lt;br /&gt;&lt;br /&gt;What’s the difference between include and require?&lt;br /&gt;It’s how they handle failures. If the file is not found by require(), it will cause a fatal error and halt the execution of the script. If the file is not found by include(), a warning will be issued, but execution will continue.&lt;br /&gt;&lt;br /&gt;How many ways can we get the value of current session id?&lt;br /&gt;session_id() returns the session id for the current session.&lt;br /&gt;How can we destroy the cookie?&lt;br /&gt;Set the cookie in past.&lt;br /&gt;&lt;br /&gt;How To Read the Entire File into a Single String?&lt;br /&gt;If you have a file, and you want to read the entire file into a single string, you can use the file_get_contents() function. It opens the specified file, reads all characters in the file, and returns them in a single string. Here is a PHP script example on how to file_get_contents():&lt;br /&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;$file = file_get_contents("/windows/system32/drivers/etc/services");&lt;br /&gt;print("Size of the file: ".strlen($file)."\n");&lt;br /&gt;?&gt;&lt;br /&gt;&lt;br /&gt;This script will print:&lt;br /&gt;&lt;br /&gt;Size of the file: 7116&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2938427049868690639-6435018884640150148?l=scriptingfaqs.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://scriptingfaqs.blogspot.com/feeds/6435018884640150148/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2938427049868690639&amp;postID=6435018884640150148' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2938427049868690639/posts/default/6435018884640150148'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2938427049868690639/posts/default/6435018884640150148'/><link rel='alternate' type='text/html' href='http://scriptingfaqs.blogspot.com/2008/07/php-interview-questions-and-answers-set.html' title='PHP Interview Questions And Answers Set II'/><author><name>Siebel Expert</name><uri>http://www.blogger.com/profile/11533458660230230361</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2938427049868690639.post-4677779726764811835</id><published>2008-07-04T08:44:00.000-07:00</published><updated>2008-12-23T03:54:08.334-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='PHP'/><category scheme='http://www.blogger.com/atom/ns#' term='Scripting Language'/><title type='text'>PHP Interview Question &amp; Answer</title><content type='html'>1. What are the differences between GET and POST methods in form submitting, give the case where we can use get and we can use post methods?&lt;br /&gt;Answer:&lt;br /&gt;On the server side, the main difference between GET and POST is where the submitted is stored. The $_GET array stores data submitted by the GET method. The $_POST array stores data submitted by the POST method.&lt;br /&gt;On the browser side, the difference is that data submitted by the GET method will be displayed in the browser's address field. Data submitted by the POST method will not be displayed anywhere on the browser.&lt;br /&gt;GET method is mostly used for submitting a small amount and less sensitive data. POST method is mostly used for submitting a large amount or sensitive data.&lt;br /&gt;2. Who is the father of php and explain the changes in php versions?&lt;br /&gt;Answer:&lt;br /&gt;Rasmus Lerdorf for version changes go to http://php.net/&lt;br /&gt;Marco Tabini is the founder and publisher of php|architect.&lt;br /&gt;3. How can we submit from without a submit button?&lt;br /&gt;Answer:&lt;br /&gt;We can use a simple JavaScript code linked to an event trigger of any form field.&lt;br /&gt;In the JavaScript code, we can call the document.form.submit() function to submit&lt;br /&gt;the form. For example:&lt;br /&gt;4. How many ways we can retrieve the date in result set of mysql Using php?&lt;br /&gt;Answer:&lt;br /&gt;As individual objects so single record or as a set or arrays.&lt;br /&gt;5. What is the difference between mysql_fetch_object and mysql_fetch_array?&lt;br /&gt;Answer:&lt;br /&gt;MySQL fetch object will collect first single matching record where mysql_fetch_array will collect all matching records from the table in an array.&lt;br /&gt;6. What is the difference between $message and $$message?&lt;br /&gt;Answer:&lt;br /&gt;They are both variables. But $message is a variable with a fixed name. $$message is a variable who's name is stored in $message. For example, if $message contains "var", $$message is the same as $var.&lt;br /&gt;7. How can we extract string 'abc.com ' from a string&lt;br /&gt;'http://info@a...' using regular _expression of php?&lt;br /&gt;Answer:&lt;br /&gt;We can use the preg_match() function with "/.*@(.*)$/" as&lt;br /&gt;the regular expression pattern. For example:&lt;br /&gt;preg_match("/.*@(.*)$/","http://info@abc.com",$data);&lt;br /&gt;echo $data[1];&lt;br /&gt;8. How can we create a database using php and mysql?&lt;br /&gt;Answer:&lt;br /&gt;PHP: mysql_create_db()&lt;br /&gt;Mysql: create database;&lt;br /&gt;9. What are the differences between require and include, include_once?&lt;br /&gt;Answer:&lt;br /&gt;File will not be included more than once. If we want to include a file once only and further calling of the file will be ignored then we have to use the PHP function include_once(). This will prevent problems with function redefinitions, variable value reassignments, etc.&lt;br /&gt;10. Can we use include ("abc.php") two times in a php page "makeit.php"?&lt;br /&gt;Answer:&lt;br /&gt;Yes we can include..&lt;br /&gt;11. What are the different tables present in mysql, which type of table is generated when we are creating a table in the following&lt;br /&gt;syntax: create table employee(eno int(2),ename varchar(10)) ?&lt;br /&gt;Answer:&lt;br /&gt;Total 5 types of tables we can create&lt;br /&gt;1. MyISAM&lt;br /&gt;2. Heap&lt;br /&gt;3. Merge&lt;br /&gt;4. InnoDB&lt;br /&gt;5. ISAM&lt;br /&gt;6. BDB&lt;br /&gt;MyISAM is the default storage engine as of MySQL 3.23.&lt;br /&gt;12. Functions in IMAP, POP3 AND LDAP?&lt;br /&gt;Answer:&lt;br /&gt;Please visit:&lt;br /&gt;http://fi2.php.net/imap&lt;br /&gt;http://uk2.php.net/ldap&lt;br /&gt;13. How can I execute a php script using command line?&lt;br /&gt;Answer:&lt;br /&gt;Just run the PHP CLI (Command Line Interface) program and provide the PHP script file name as the command line argument. For example, "php myScript.php", assuming "php" is the command to invoke the CLI program.&lt;br /&gt;Be aware that if your PHP script was written for the Web CGI interface, it may not execute properly in command line environment.&lt;br /&gt;14. Suppose your ZEND engine supports the mode &lt;? ?&gt; Then how can u configure your php ZEND engine to support &lt;?php ?&gt; mode ?&lt;br /&gt;Answer:&lt;br /&gt;If you change the line: short_open_tag = off in php.ini file. Then your php ZEND engine support only &lt;?php ?&gt; mode.&lt;br /&gt;15. Shopping cart online validation i.e. how can we configure the paypals?&lt;br /&gt;16. What is meant by nl2br()?&lt;br /&gt;Answer:&lt;br /&gt;nl2br -- Inserts HTML line breaks before all newlines in a string&lt;br /&gt;string nl2br (string); Returns string with '&lt;br /&gt;' inserted before all newlines.&lt;br /&gt;For example: echo nl2br("god bless\n you") will output "god bless&lt;br /&gt;\n you" to your browser.&lt;br /&gt;17. Draw the architecture of ZEND engine?&lt;br /&gt;18. What are the current versions of apache, php, and mysql?&lt;br /&gt;Answer:&lt;br /&gt;PHP: php5.1.2&lt;br /&gt;MySQL: MySQL 5.1&lt;br /&gt;Apache: Apache 2.1&lt;br /&gt;19. What are the reasons for selecting lamp (Linux, apache, mysql, php) instead of combination of other software programs, servers and operating systems?&lt;br /&gt;Answer:&lt;br /&gt;All of those are open source resource. Security of linux is very very more than windows. Apache is a better server that IIS both in functionality and security. Mysql is world most popular open source database. Php is more faster that asp or any other scripting language.&lt;br /&gt;20. How can we encrypt and decrypt a data present in a mysql table using mysql?&lt;br /&gt;Answer:&lt;br /&gt;AES_ENCRYPT () and AES_DECRYPT ()&lt;br /&gt;21. How can we encrypt the username and password using php?&lt;br /&gt;Answer:&lt;br /&gt;You can encrypt a password with the following Mysql&gt;SET PASSWORD=PASSWORD("Password");&lt;br /&gt;We can encode data using base64_encode($string) and can decode using base64_decode($string);&lt;br /&gt;22. What are the features and advantages of OBJECT ORIENTED PROGRAMMING?&lt;br /&gt;Answer:&lt;br /&gt;One of the main advantages of OO programming is its ease of modification; objects can easily be modified and added to a system there by reducing maintenance costs. OO programming is also considered to be better at modeling the real world than is procedural programming. It allows for more complicated and flexible interactions. OO systems are also easier for non-technical personnel to understand and easier for them to participate in the maintenance and enhancement of a system because it appeals to natural human cognition patterns.&lt;br /&gt;For some systems, an OO approach can speed development time since many objects are standard across systems and can be reused. Components that manage dates, shipping, shopping carts, etc. can be purchased and easily modified for a specific system.&lt;br /&gt;23. What are the differences between PROCEDURE ORIENTED LANGUAGES&lt;br /&gt;AND OBJECT ORIENTED LANGUAGES?&lt;br /&gt;Answer:&lt;br /&gt;Traditional programming has the following characteristics:&lt;br /&gt;Functions are written sequentially, so that a change in programming can affect any code that follows it.&lt;br /&gt;If a function is used multiple times in a system (i.e., a piece of code that manages the date), it is often simply cut and pasted into each program (i.e., a change log, order function, fulfillment system, etc). If a date change is needed (i.e., Y2K when the code needed to be changed to handle four numerical digits instead of two), all these pieces of code must be found, modified, and tested.&lt;br /&gt;Code (sequences of computer instructions) and data (information on which the instructions operates on) are kept separate. Multiple sets of code can access and modify one set of data. One set of code may rely on data in multiple places. Multiple sets of code and data are required to work together. Changes made to any of the code sets and data sets can cause problems through out the system.&lt;br /&gt;Object-Oriented programming takes a radically different approach:&lt;br /&gt;Code and data are merged into one indivisible item – an object (the term “component” has also been used to describe an object.) An object is an abstraction of a set of real-world things (for example, an object may be created around “date”) The object would contain all information and functionality for that thing (A date&lt;br /&gt;object it may contain labels like January, February, Tuesday, Wednesday. It may contain functionality that manages leap years, determines if it is a business day or a holiday, etc., See Fig. 1). Ideally, information about a particular thing should reside in only one place in a system. The information within an object is encapsulated (or hidden) from the rest of the system.&lt;br /&gt;A system is composed of multiple objects (i.e., date function, reports, order processing, etc., See Fig 2). When one object needs information from another object, a request is sent asking for specific information. (for example, a report object may need to know what today’s date is and will send a request to the date object) These requests are called messages and each object has an interface that manages messages.&lt;br /&gt;OO programming languages include features such as “class”, “instance”, “inheritance”, and “polymorphism” that increase the power and flexibility of an object.&lt;br /&gt;24. What is the use of friend function?&lt;br /&gt;Answer:&lt;br /&gt;Friend functions&lt;br /&gt;Sometimes a function is best shared among a number of different classes. Such functions can be declared either as member functions of one class or as global functions. In either case they can be set to be friends of other classes, by using a friend specifier in the class that is admitting them. Such functions can use all attributes of the class whichnames them as a friend, as if they were themselves members of that class.&lt;br /&gt;A friend declaration is essentially a prototype for a member function, but instead of requiring an implementation with the name of that class attached by the double colon syntax, a global function or member function of another class provides the match.&lt;br /&gt;class mylinkage {&lt;br /&gt;private:&lt;br /&gt;mylinkage * prev;&lt;br /&gt;mylinkage * next;&lt;br /&gt;protected:&lt;br /&gt;friend void set_prev(mylinkage* L, mylinkage* N);&lt;br /&gt;void set_next(mylinkage* L);&lt;br /&gt;public:&lt;br /&gt;mylinkage * succ();&lt;br /&gt;mylinkage * pred();&lt;br /&gt;mylinkage();&lt;br /&gt;};&lt;br /&gt;void mylinkage::set_next(mylinkage* L) { next = L; }&lt;br /&gt;void set_prev(mylinkage * L, mylinkage * N ) { N-&gt;prev = L; }&lt;br /&gt;Friends in other classes&lt;br /&gt;It is possible to specify a member function of another class as a friend as follows:&lt;br /&gt;class C {&lt;br /&gt;friend int B::f1();&lt;br /&gt;};&lt;br /&gt;class B {&lt;br /&gt;int f1();&lt;br /&gt;};&lt;br /&gt;It is also possible to specify all the functions in another class as friends, by specifying the entire class as a friend.&lt;br /&gt;class A {&lt;br /&gt;friend class B;&lt;br /&gt;};&lt;br /&gt;Friend functions allow binary operators to be defined which combine private data in a pair of objects. This is particularly powerful when using the operator overloading features of C++. We will return to it when we look at overloading.&lt;br /&gt;25. What are the differences between public, private, protected, static, transient, final and volatile?&lt;br /&gt;element Class Interface&lt;br /&gt;Data field Method Constructor&lt;br /&gt;modifier top level nested top level nested&lt;br /&gt;(outer) (inner) (outer) (inner)&lt;br /&gt;final yes yes no yes yes no no&lt;br /&gt;private yes yes yes no yes no yes&lt;br /&gt;protected yes yes yes no yes no yes&lt;br /&gt;public yes yes yes yes yes yes yes&lt;br /&gt;static yes yes no no yes no yes&lt;br /&gt;transient yes no no no no no no&lt;br /&gt;volatile yes no no no no no no&lt;br /&gt;26. What are the different types of errors in php?&lt;br /&gt;Answer:&lt;br /&gt;Three are three types of errors:&lt;br /&gt;1. Notices: These are trivial, non-critical errors that PHP encounters while executing a script - for example, accessing a variable that has not yet been defined. By default, such errors are not displayed to the user at all - although, as you will see, you can change this default behaviour.&lt;br /&gt;2. Warnings: These are more serious errors - for example, attempting to include() a file which does not exist. By default, these errors are displayed to the user, but they do not result in script termination.&lt;br /&gt;3. Fatal errors: These are critical errors - for example, instantiating an object of a non-existent class, or calling a non-existent function. These errors cause the immediate termination of the script, and PHP's default behaviour is to display them to the user when they take place.&lt;br /&gt;27. What is the functionality of the function strstr and stristr?&lt;br /&gt;Answer:&lt;br /&gt;strstr() returns part of a given string from the first occurrence of a given substring to the end of the string. For example: strstr("user@example.com","@") will return "@example.com".&lt;br /&gt;stristr() is idential to strstr() except that it is case insensitive.&lt;br /&gt;28. What are the differences between PHP 3 and PHP 4 and PHP 5?&lt;br /&gt;Answer:&lt;br /&gt;Go read the release notes at http://php.net.&lt;br /&gt;29. How can we convert asp pages to php pages?&lt;br /&gt;Answer:&lt;br /&gt;You can download asp2php front-end application from the site http://asp2php.naken.cc.&lt;br /&gt;30. What is the functionality of the function htmlentities? Answer: htmlentities -- Convert all applicable characters to HTML entities&lt;br /&gt;This function is identical to htmlspecialchars() in all ways, except with htmlentities(), all characters which have HTML character entity equivalents are translated into these entities.&lt;br /&gt;31. How can we get second of the current time using date function?&lt;br /&gt;Answer:&lt;br /&gt;$second = date(“s”);&lt;br /&gt;32. How can we convert the time zones using php?&lt;br /&gt;Answer:&lt;br /&gt;&lt;?&lt;br /&gt;echo "Original Time: ". date("h:i:s")."\n";&lt;br /&gt;putenv("TZ=US/Eastern");&lt;br /&gt;echo "New Time: ". date("h:i:s")."\n";&lt;br /&gt;?&gt;&lt;br /&gt;33. What is meant by urlencode and urldocode?&lt;br /&gt;Answer:&lt;br /&gt;urlencode() returns the URL encoded version of the given string. URL coding converts special characters into % signs followed by two hex digits. For example: urlencode("10.00%") will return "10%2E00%25". URL encoded strings are safe to be used as part of URLs.&lt;br /&gt;urldecode() returns the URL decoded version of the given string.&lt;br /&gt;34. What is the difference between the functions unlink and unset?&lt;br /&gt;Answer:&lt;br /&gt;unlink() deletes the given file from the file system.&lt;br /&gt;unset() makes a variable undefined.&lt;br /&gt;35. How can we register the variables into a session?&lt;br /&gt;Answer:&lt;br /&gt;We can use the session_register ($ur_session_var) function.&lt;br /&gt;36. How can we get the properties (size, type, width, height) of an image using php image functions?&lt;br /&gt;Answer:&lt;br /&gt;To know the Image type use exif_imagetype () function&lt;br /&gt;To know the Image size use getimagesize () function&lt;br /&gt;To know the image width use imagesx () function&lt;br /&gt;To know the image height use imagesy() function&lt;br /&gt;37. How can we get the browser properties using php?&lt;br /&gt;Answer:&lt;br /&gt;&lt;?php&lt;br /&gt;echo $_SERVER['HTTP_USER_AGENT'] . "\n\n";&lt;br /&gt;$browser = get_browser(null, true);&lt;br /&gt;print_r($browser);&lt;br /&gt;?&gt;&lt;br /&gt;38. What is the maximum size of a file that can be uploaded using php and how can we change this?&lt;br /&gt;Answer:&lt;br /&gt;You can change maximum size of a file set upload_max_filesize variable in php.ini file&lt;br /&gt;39. How can we increase the execution time of a php script?&lt;br /&gt;Answer:&lt;br /&gt;Set max_execution_time variable in php.ini file to your desired time in second.&lt;br /&gt;40. How can we take a backup of a mysql table and how can we restore it.?&lt;br /&gt;Answer: Create a full backup of your database: shell&gt; mysqldump --tab=/path/to/some/dir --opt db_name Or: shell&gt; mysqlhotcopy db_name /path/to/some/dir&lt;br /&gt;The full backup file is just a set of SQL statements, so restoring it is very easy:&lt;br /&gt;shell&gt; mysql &lt; backup_sunday_1_PM.sql&lt;br /&gt;41. How can we optimize or increase the speed of a mysql select query?&lt;br /&gt;Answer:&lt;br /&gt;In general, when you want to make a slow SELECT … WHERE query faster, the first thing to check is whether you can add an index. All references between different tables should usually be done with indexes. You can use the EXPLAIN statement to determine which indexes are used for a SELECT.&lt;br /&gt;Some general tips for speeding up queries on MyISAM tables:&lt;br /&gt;A: To help MySQL better optimize queries, use ANALYZE TABLE or run myisamchk --analyze on a table after it has been loaded with data. This updates a value for each index part that indicates the average number of rows that have the same value. (For unique indexes, this is always 1.) MySQL uses this to decide which index to choose when you join two tables based on a non-constant expression. You can check the result from the table analysis by using SHOW INDEX FROM tbl_name and examining the Cardinality value. myisamchk --description --verbose shows index distribution information.&lt;br /&gt;42. How many ways can we get the value of current session id?&lt;br /&gt;Answer:&lt;br /&gt;session_id() returns the session id for the current session.&lt;br /&gt;43. How can we destroy the session, how can we unset the variable of a session?&lt;br /&gt;Answer:&lt;br /&gt;session_unregister() unregisters a global variable from the current session.&lt;br /&gt;session_unset() frees all session variables.&lt;br /&gt;44. How can we destroy the cookie?&lt;br /&gt;Answer::&lt;br /&gt;Set the cookie in past.&lt;br /&gt;45. How many ways we can pass the variable through the navigation between the pages?&lt;br /&gt;Answer:&lt;br /&gt;At least 3 ways:&lt;br /&gt;a) Register the variable into the session&lt;br /&gt;b) Pass the variable as a cookie&lt;br /&gt;c) Pass the variable as part of the URL&lt;br /&gt;46. What is the difference between ereg_replace() and eregi_replace()?&lt;br /&gt;Answer:&lt;br /&gt;eregi_replace() function is identical to ereg_replace() except that this ignores case distinction when matching alphabetic characters.&lt;br /&gt;47. What are the different functions in sorting an array?&lt;br /&gt;Answer:&lt;br /&gt;Sorting functions in PHP:&lt;br /&gt;asort()&lt;br /&gt;arsort()&lt;br /&gt;ksort()&lt;br /&gt;krsort()&lt;br /&gt;uksort()&lt;br /&gt;sort()&lt;br /&gt;natsort()&lt;br /&gt;rsort()&lt;br /&gt;48. How can we know the count/number of elements of an array?&lt;br /&gt;Answer:&lt;br /&gt;2 ways:&lt;br /&gt;a) sizeof($urarray) This function is an alias of count()&lt;br /&gt;b) count($urarray)&lt;br /&gt;Interestingly if u just pass a simple var instead of a an array it will return 1.&lt;br /&gt;49. What is the php predefined variable that tells the What types of images that php supports?&lt;br /&gt;Answer: $_SERVER['HTTP_ACCEPT']&lt;br /&gt;50. How can I know that a variable is a number or not using a _JavaScript?&lt;br /&gt;Answer:&lt;br /&gt;function IsNumeric(sText)&lt;br /&gt;{&lt;br /&gt;var ValidChars = "0123456789.";&lt;br /&gt;var IsNumber=true;&lt;br /&gt;var Char;&lt;br /&gt;for (i = 0; i &lt; sText.length &amp;amp;&amp;amp; IsNumber == true; i++)&lt;br /&gt;{&lt;br /&gt;Char = sText.charAt(i);&lt;br /&gt;if (ValidChars.indexOf(Char) == -1)&lt;br /&gt;{&lt;br /&gt;IsNumber = false;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;return IsNumber;&lt;br /&gt;}&lt;br /&gt;51. List out some tools through which we can draw E-R diagrams for mysql.&lt;br /&gt;Answer:&lt;br /&gt;Dbdesigner, conceptdraw etc.&lt;br /&gt;52. How can I retrieve values from one database server and store&lt;br /&gt;them in other database server using php?&lt;br /&gt;Answer:&lt;br /&gt;&lt;?php&lt;br /&gt;db_connect($host,$user,$pwd)&lt;br /&gt;{&lt;br /&gt;$host_name=$host;&lt;br /&gt;$user=$user;&lt;br /&gt;$pwd=$pwd;&lt;br /&gt;$link1 = mysql_connect($host_name, $user, $pwd);&lt;br /&gt;if (!$link1) {&lt;br /&gt;die('Could not connect: ' . mysql_error());&lt;br /&gt;}&lt;br /&gt;return($link1);&lt;br /&gt;}&lt;br /&gt;$link1 =db_connect(hostname, username, password);&lt;br /&gt;$im=mysql_select_db("test") or mysql_error();&lt;br /&gt;$result1=mysql_query("select * from student")or mysql_error();&lt;br /&gt;while ($row = mysql_fetch_array($result1)) {&lt;br /&gt;$id=$row["id"];&lt;br /&gt;$name=$row["name"];&lt;br /&gt;$roll=$row["roll"];&lt;br /&gt;}&lt;br /&gt;mysql_close($link1);&lt;br /&gt;$link2 = db_connect(hostname, username, password);&lt;br /&gt;$im1=mysql_select_db("test1") or die(mysql_error());&lt;br /&gt;//$query1="insert into student1('name','roll','address') values($id,$name,$roll)";&lt;br /&gt;$result1=mysql_query("insert into student1 values('$id','$name','$roll')") or die(mysql_error());&lt;br /&gt;echo "&lt;br /&gt;"."Executed";&lt;br /&gt;mysql_close($link2);&lt;br /&gt;?&gt;&lt;br /&gt;53. List out the predefined classes in php?&lt;br /&gt;Answer:&lt;br /&gt;Directory&lt;br /&gt;stdClass&lt;br /&gt;__PHP_Incomplete_Class&lt;br /&gt;exception&lt;br /&gt;php_user_filter&lt;br /&gt;54. How can I make a script that can be bilanguage (supports Eglish, German)?&lt;br /&gt;Answer :&lt;br /&gt;&lt;meta equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;&lt;br /&gt;You can change charset variable in above line in the script to support bilanguage.&lt;br /&gt;55. What are the difference between abstract class and interface?&lt;br /&gt;Abstract class: abstract classes are the class where one or more methods are abstract but not necessarily all method has to be abstract. Abstract methods are the methods, which are declare in its class but not define. The definition of those methods must be in its extending class.&lt;br /&gt;Interface: Interfaces are one type of class where all the methods are abstract. That means all the methods only declared but not defined. All the methods must be define by its implemented class.&lt;br /&gt;56. How can we send mail-using _JavaScript?&lt;br /&gt;Answer:&lt;br /&gt;NO! JavaScript can't email a form! but, there are alternatives to send the form data to an email address.&lt;br /&gt;Try this:&lt;br /&gt;&lt;form action="mailto:you@yourdmainhere.com" method="post" enctype="text/plain"&gt;&lt;br /&gt;FirstName:&lt;input type="text" name="FirstName"&gt;&lt;br /&gt;Email:&lt;input type="text" name="Email"&gt;&lt;br /&gt;&lt;input type="submit" name="submit" value="Submit"&gt;&lt;br /&gt;&lt;/form&gt;&lt;br /&gt;57. How can we repair a mysql table?&lt;br /&gt;Answer:&lt;br /&gt;The syntex for repairing a mysql table is&lt;br /&gt;REPAIR TABLENAME, [TABLENAME, ], [Quick],[Extended]&lt;br /&gt;This command will repair the table specified&lt;br /&gt;if the quick is given the mysql will do a repair of only the index tree if the extended is given it will create index row by row&lt;br /&gt;58. What are the advantages of stored procedures, triggers, indexes?&lt;br /&gt;A stored procedure is a set of SQL commands that can be compiled and stored in the server. Once this has been done, clients don't need to keep re-issuing the entire query but can refer to the stored procedure. This provides better overall performance because the query has to be parsed only once, and less information needs to be sent between the server and the client. You can also raise the conceptual level by having libraries of functions in the server. However, stored procedures of course do increase the load on the database server system, as more of the work is done on the server side and less on the client (application) side.&lt;br /&gt;Triggers will also be implemented. A trigger is effectively a type of stored procedure, one that is invoked when a particular event occurs. For example, you can install a stored procedure that is triggered each time a record is deleted from a transaction table and that stored procedure automatically deletes the corresponding customer from a customer table when all his transactions are deleted.&lt;br /&gt;Indexes are used to find rows with specific column values quickly. Without an index, MySQL must begin with the first row and then read through the entire table to find the relevant rows. The larger the table, the more this costs. If the table has an index for the columns in question, MySQL can quickly determine the position to seek to in the middle of the data file without having to look at all the data. If a table has 1,000 rows, this is at least 100 times faster than reading sequentially. If you need to access most of the rows, it is faster to read sequentially, because this minimizes disk seeks.&lt;br /&gt;59. What is the maximum length of a table name, database name, and fieldname in mysql?&lt;br /&gt;Answer:&lt;br /&gt;Database name- 64&lt;br /&gt;Table name -64&lt;br /&gt;Fieldname-64&lt;br /&gt;60. How many values can the SET function of mysql takes?&lt;br /&gt;Answer:&lt;br /&gt;Mysql set can take zero or more values but at the maximum it can take 64 values&lt;br /&gt;61. What are the other commands to know the structure of table using mysql commands except explain command?&lt;br /&gt;Answer:&lt;br /&gt;describe table_name;&lt;br /&gt;62. How many tables will create when we create table, what are they?&lt;br /&gt;Answer:&lt;br /&gt;3 tables will create when we create table. They are&lt;br /&gt;The `.frm' file stores the table definition.&lt;br /&gt;The data file has a `.MYD' (MYData) extension.&lt;br /&gt;The index file has a `.MYI' (MYIndex) extension,&lt;br /&gt;63. What is the purpose of the following files having extensions 1) frm 2) MYD 3) MYI. What these files contains?&lt;br /&gt;Answer:&lt;br /&gt;In MySql, the default table type is MyISAM.&lt;br /&gt;Each MyISAM table is stored on disk in three files. The files have names that begin with the table name and have an extension to indicate the file type.&lt;br /&gt;The `.frm' file stores the table definition.&lt;br /&gt;The data file has a `.MYD' (MYData) extension.&lt;br /&gt;The index file has a `.MYI' (MYIndex) extension,&lt;br /&gt;64. What is maximum size of a database in mysql?&lt;br /&gt;Answer:&lt;br /&gt;If the operating system or filesystem places a limit on the number of files in a directory, MySQL is bound by that constraint.&lt;br /&gt;The efficiency of the operating system in handling large numbers of files in a directory can place a practical limit on the number of tables in a database. If the time required to open a file in the directory increases significantly as the number of files increases, database performance can be adversely affected.&lt;br /&gt;The amount of available disk space limits the number of tables.&lt;br /&gt;MySQL 3.22 had a 4GB (4 gigabyte) limit on table size. With the MyISAM storage engine in MySQL 3.23, the maximum table size was increased to 65536 terabytes (2567 – 1 bytes). With this larger allowed table size, the maximum effective table size for MySQL databases is usually determined by operating system constraints on file sizes, not by MySQL internal limits.&lt;br /&gt;The InnoDB storage engine maintains InnoDB tables within a tablespace that can be created from several files. This allows a table to exceed the maximum individual file size. The tablespace can include raw disk partitions, which allows extremely large tables. The maximum tablespace size is 64TB.&lt;br /&gt;The following table lists some examples of operating system file-size limits. This is only a rough guide and is not intended to be definitive. For the most up-to-date information, be sure to check the documentation specific to your operating system.&lt;br /&gt;Operating System File-size Limit&lt;br /&gt;Linux 2.2-Intel 32-bit 2GB (LFS: 4GB)&lt;br /&gt;Linux 2.4+ (using ext3 filesystem) 4TB&lt;br /&gt;Solaris 9/10 16TB&lt;br /&gt;NetWare w/NSS filesystem 8TB&lt;br /&gt;Win32 w/ FAT/FAT32 2GB/4GB&lt;br /&gt;Win32 w/ NTFS 2TB (possibly larger)&lt;br /&gt;MacOS X w/ HFS+ 2TB&lt;br /&gt;65. Give the syntax of Grant and Revoke commands?&lt;br /&gt;The generic syntax for grant is as following&lt;br /&gt;&gt; GRANT [rights] on [database/s] TO [username@hostname] IDENTIFIED BY [password]&lt;br /&gt;now rights can be&lt;br /&gt;a) All privilages&lt;br /&gt;b) combination of create, drop, select, insert, update and delete etc.&lt;br /&gt;we can grant rights on all databse by usingh *.* or some specific database by database.* or a specific table by database.table_name&lt;br /&gt;username@hotsname can be either username@localhost, username@hostname and username@%&lt;br /&gt;where hostname is any valid hostname and % represents any name, the *.* any condition&lt;br /&gt;password is simply the password of user&lt;br /&gt;The generic syntax for revoke is as following&lt;br /&gt;&gt; REVOKE [rights] on [database/s] FROM [username@hostname]&lt;br /&gt;now rights can be as explained above&lt;br /&gt;a) All privilages&lt;br /&gt;b) combination of create, drop, select, insert, update and delete etc.&lt;br /&gt;username@hotsname can be either username@localhost, username@hostname and username@%&lt;br /&gt;where hostname is any valid hostname and % represents any name, the *.* any condition&lt;br /&gt;66. Explain Normalization concept?&lt;br /&gt;The normalization process involves getting our data to conform to three progressive normal forms, and a higher level of normalization cannot be achieved until the previous levels have been achieved (there are actually five normal forms, but the last two are mainly academic and will not be discussed).&lt;br /&gt;First Normal Form&lt;br /&gt;The First Normal Form (or 1NF) involves removal of redundant data from horizontal rows. We want to ensure that there is no duplication of data in a given row, and that every column stores the least amount of information possible (making the field atomic).&lt;br /&gt;Second Normal Form&lt;br /&gt;Where the First Normal Form deals with redundancy of data across a horizontal row, Second Normal Form (or 2NF) deals with redundancy of data in vertical columns. As stated earlier, the normal forms are progressive, so to achieve Second Normal Form, your tables must already be in First Normal Form.&lt;br /&gt;Third Normal Form&lt;br /&gt;I have a confession to make; I do not often use Third Normal Form. In Third Normal Form we are looking for data in our tables that is not fully dependant on the primary key, but dependant on another value in the table&lt;br /&gt;67. How can we find the number of rows in a table using mysql?&lt;br /&gt;Answer: Use this for mysql&lt;br /&gt;&gt;SELECT COUNT(*) FROM table_name;&lt;br /&gt;but if u r particular about no of rows with some special result&lt;br /&gt;do this&lt;br /&gt;&gt;SELECT [colms],COUNT(*) FROM table_name [where u put conditions];&lt;br /&gt;68. How can we find the number of rows in a result set using php?&lt;br /&gt;Answer: for PHP&lt;br /&gt;$result = mysql_query($any_valid_sql, $database_link);&lt;br /&gt;$num_rows = mysql_num_rows($result);&lt;br /&gt;echo “$num_rows rows found”;&lt;br /&gt;69. How many ways we can we find the current date using mysql?&lt;br /&gt;Answer:&lt;br /&gt;SELECT CURDATE();&lt;br /&gt;CURRENT_DATE() = CURDATE()&lt;br /&gt;for time use&lt;br /&gt;SELECT CURTIME();&lt;br /&gt;CURRENT_TIME() = CURTIME()&lt;br /&gt;70. What are the advantages and disadvantages of CASCADE STYLE SHEETS?&lt;br /&gt;External Style Sheets&lt;br /&gt;Advantages&lt;br /&gt;Can control styles for multiple documents at once&lt;br /&gt;Classes can be created for use on multiple HTML element types in many documents&lt;br /&gt;Selector and grouping methods can be used to apply styles under complex contexts&lt;br /&gt;Disadvantages&lt;br /&gt;An extra download is required to import style information for each document&lt;br /&gt;The rendering of the document may be delayed until the external style sheet is loaded&lt;br /&gt;Becomes slightly unwieldy for small quantities of style definitions&lt;br /&gt;Embedded Style Sheets&lt;br /&gt;Advantages&lt;br /&gt;Classes can be created for use on multiple tag types in the document&lt;br /&gt;Selector and grouping methods can be used to apply styles under complex contexts&lt;br /&gt;No additional downloads necessary to receive style information&lt;br /&gt;Disadvantages&lt;br /&gt;This method can not control styles for multiple documents at once&lt;br /&gt;Inline Styles&lt;br /&gt;Advantages&lt;br /&gt;Useful for small quantities of style definitions&lt;br /&gt;Can override other style specification methods at the local level so only exceptions need to be listed in conjunction with other style methods&lt;br /&gt;Disadvantages&lt;br /&gt;Does not distance style information from content (a main goal of SGML/HTML)&lt;br /&gt;Can not control styles for multiple documents at once&lt;br /&gt;Author can not create or control classes of elements to control multiple element types within the document&lt;br /&gt;Selector grouping methods can not be used to create complex element addressing scenarios&lt;br /&gt;71. What type of inheritance that php supports? Answer: In PHP an extended class is always dependent on a single base class, that is, multiple inheritance is not supported. Classes are extended using the keyword 'extends'.&lt;br /&gt;Usage:&lt;br /&gt;&lt;?php classNamedCartextendsCart{&lt;br /&gt;var $owner; function set_owner ($name) { $this-&gt;owner = $name; } } ?&gt;&lt;br /&gt;72. How can increase the performance of mysql select query?&lt;br /&gt;The structure of table view buyers is as follows&lt;br /&gt;+----------------+-------------+------+-----+---------+----------------+&lt;br /&gt;| Field | Type | Null | Key | Default | Extra |&lt;br /&gt;+----------------+-------------+------+-----+---------+----------------+&lt;br /&gt;| user_pri_id | int(15) | | PRI | NULL | auto_increment |&lt;br /&gt;| userid | varchar(10) | YES | | NULL | |&lt;br /&gt;+----------------+-------------+------+-----+---------+----------------+&lt;br /&gt;the value of user_pri_id the last row 2345 then What will happen in&lt;br /&gt;the following conditions&lt;br /&gt;Condition1: Delete all the rows and insert another row then What is&lt;br /&gt;the starting value for this auto incremented field user_pri_id ,&lt;br /&gt;Condition2: Delete the last row(having the field value 2345) and&lt;br /&gt;insert another row then What is the value for this auto incremented&lt;br /&gt;field user_pri_id&lt;br /&gt;Answer:&lt;br /&gt;In general, when you want to make a slow SELECT ... WHERE query faster, the first thing to check is whether you can add an index. All references between different tables should usually be done with indexes. You can use the EXPLAIN statement to determine which indexes are used for a SELECT. See section 7.4.5 How MySQL Uses Indexes and section 7.2.1 EXPLAIN Syntax (Get Information About a SELECT).&lt;br /&gt;Some general tips for speeding up queries on MyISAM tables:&lt;br /&gt;To help MySQL optimize queries better, use ANALYZE TABLE or run myisamchk --analyze on a table after it has been loaded with data. This updates a value for each index part that indicates the average number of rows that have the same value. (For unique indexes, this is always 1.) MySQL will use this to decide which index to choose when you join two tables based on a non-constant expression. You can check the result from the table analysis by using SHOW INDEX FROM tbl_name and examining the Cardinality value. myisamchk --description --verbose shows index distribution information.&lt;br /&gt;To sort an index and data according to an index, use myisamchk --sort-index --sort-records=1 (if you want to sort on index 1). This is a good way to make queries faster if you have a unique index from which you want to read all records in order&lt;br /&gt;according to the index. Note that the first time you sort a large table this way, it may take a long time.&lt;br /&gt;In both cases let the value for auto increment field be n then next row will have value n+1 i.e. 2346&lt;br /&gt;73. What are the advantages/disadvantages of mysql and php?&lt;br /&gt;Answer:&lt;br /&gt;Both of them are open source software (so free of cost), support cross platform. php is faster then ASP and JSP.&lt;br /&gt;74. What is the difference between GROUP BY and ORDER BY in Sql?&lt;br /&gt;Answer:&lt;br /&gt;To sort a result, use an ORDER BY clause.&lt;br /&gt;The most general way to satisfy a GROUP BY clause is to scan the whole table and create a new temporary table where all rows from each group are consecutive, and then use this temporary table to discover groups and apply aggregate functions (if any).&lt;br /&gt;ORDER BY [col1],[col2],…,[coln]; Tels DBMS according to what columns it should sort the result. If two rows will hawe the same value in col1 it will try to sort them according to col2 and so on.&lt;br /&gt;GROUP BY [col1],[col2],…,[coln]; Tels DBMS to group results with same value of column col1. You can use COUNT(col1), SUM(col1), AVG(col1) with it, if you want to count all items in group, sum all values or view average&lt;br /&gt;75. What is the difference between char and varchar data types?&lt;br /&gt;Answer:&lt;br /&gt;char(M) M bytes 0&lt;=M&lt;=255&lt;br /&gt;varchar(M) L+1 bytes where L&lt;=M &amp;amp; 0&lt;=M&lt;=255&lt;br /&gt;i.e.; char data type allocate memory statically&lt;br /&gt;and varchar data type allocate memory dynamically&lt;br /&gt;76. What is the functionality of md5 function in php?&lt;br /&gt;Answer:&lt;br /&gt;string md5(string)&lt;br /&gt;Calculate the md5 hash of a string. The hash is a 32-character hexadecimal number. We can use it to generate keys, which we use to identify users etc. If we add random no techniques to it the md5 generated now will be totally different for the same string we are using..&lt;br /&gt;77. How can I load data from a text file into a table?&lt;br /&gt;Answer:&lt;br /&gt;The mysql provides a LOAD DATA INFILE syntax. U can load data from a file. Gr8 tool but u need to make sure that&lt;br /&gt;a) data is delimited&lt;br /&gt;b) u match the colms and data correctly&lt;br /&gt;dont use w/out first learning the syntax&lt;br /&gt;78. How can we know the number of days between two given dates using mysql?&lt;br /&gt;Answer:&lt;br /&gt;select DIFFDATE( NOW(), ‘yyyy-mm-dd’ );&lt;br /&gt;79. How can we know the number of days between two given dates using php?&lt;br /&gt;Answer:&lt;br /&gt;&lt;?php&lt;br /&gt;$tomorrow = mktime(0, 0, 0, date("m") , date("d")+1, date("Y"));&lt;br /&gt;$lastmonth = mktime(0, 0, 0, date("m")-1, date("d"), date("Y"));&lt;br /&gt;echo ($tomorrow-$lastmonth)/86400;&lt;br /&gt;?&gt;&lt;br /&gt;80. How can we change the name of a column of a table?&lt;br /&gt;Answer:&lt;br /&gt;MySQL query to rename table: RENAME TABLE tbl_name TO new_tbl_name&lt;br /&gt;[, tbl_name2 TO new_tbl_name2] ...&lt;br /&gt;or,&lt;br /&gt;ALTER TABLE tableName CHANGE OldName newName.&lt;br /&gt;81. How can we change the name and data type of a column of a table?&lt;br /&gt;Answer:&lt;br /&gt;ALTER [IGNORE] TABLE tbl_name&lt;br /&gt;alter_specification [, alter_specification] | CHANGE [COLUMN] old_col_name column_definition&lt;br /&gt;[FIRST|AFTER col_name]&lt;br /&gt;82. What are the differences between drop a table and truncate a table?&lt;br /&gt;Answer: Delete a Table or DatabaseTo delete a table (the table structure, attributes, and indexes will also be deleted).&lt;br /&gt;What if we only want to get rid of the data inside a table, and not the table itself? Use the TRUNCATE TABLE command (deletes only the data inside the table).&lt;br /&gt;83. When you want to show some part of a text displayed on an HTML page in red font color, what different possibilities are there to do this? What are the advantages/disadvantages of these methods?&lt;br /&gt;Answer:&lt;br /&gt;Using Html font color tag:&lt;br /&gt;&lt;span style="color:RED;"&gt; I am Amin &lt;/span&gt;&lt;br /&gt;Using tag in CSS:&lt;br /&gt;STRONG {color:red}&lt;br /&gt;So when we use the &lt;strong&gt; tag:&lt;br /&gt;I am &lt;strong&gt;Amin&lt;/strong&gt; about this.&lt;br /&gt;Using Class in CSS:&lt;br /&gt;.colorclass&lt;br /&gt;{&lt;br /&gt;color:#FF3399;&lt;br /&gt;font-weight:900;&lt;br /&gt;}&lt;br /&gt;I am &lt;span class="colorclass"&gt;Amin&lt;/span&gt;&lt;br /&gt;If we use html the modification will be trouble some because we have to change the code of the page. But when we use CSS then it will be easy to change the CSS file and we can get the desired out put.&lt;br /&gt;84. When viewing an HTML page in a Browser, the Browser often keeps this page in its cache. What can be possible advantages/disadvantages of page caching? How can you prevent caching of a certain page (please give several alternate solutions)?&lt;br /&gt;Answer:&lt;br /&gt;When you use the &lt;http-equiv="pragma" content="NO-CACHE"&gt; metatag in the&lt;br /&gt;header section at the beginning of an HTML Web page, the Web page may&lt;br /&gt;still be cached in the Temporary Internet Files folder.&lt;br /&gt;A page that Internet Explorer is browsing is not cached until half of the 64 KB&lt;br /&gt;&gt; buffer is filled. Usually, metatags are inserted in the header section of an&lt;br /&gt;&gt; HTML document, which appears at the beginning of the document. When the HTML code is parsed, it is read from top to bottom. When the&lt;br /&gt;&lt;HTTP-EQUIV="PRAGMA"&lt;br /&gt;CONTENT="NO-CACHE"&gt; metatag is read, Internet Explorer looks for the&lt;br /&gt;existence of the page in cache at that exact moment. If it is there, it is removed. To properly prevent the Web page from appearing in the cache, place another header section at the end of the HTML ocument. For example:&lt;br /&gt;&lt;/body&gt;&lt;br /&gt;&lt;head&gt;&lt;br /&gt;&lt;meta equiv="PRAGMA" content="NO-CACHE"&gt;&lt;br /&gt;&lt;/head&gt;&lt;br /&gt;&lt;/html&gt;&lt;br /&gt;85. What are the different methods of passing data or information between two calls of a web page? What are the advantages/disadvantages of these methods?&lt;br /&gt;86. An Apache web server is running on a Linux system. Suddenly, the web server delivers the pages very slow. How could you find out possible reasons for that (when using system commands, please specify their names)?&lt;br /&gt;87. What are the different ways to login to a remote server? Explain the means, advantages and disadvantages?&lt;br /&gt;Answer:&lt;br /&gt;There is at least 3 ways to logon to a remote server:&lt;br /&gt;Use ssh or telnet if you concern with security&lt;br /&gt;You can also use rlogin to logon to a remote server.&lt;br /&gt;88. Please give a regular _expression (preferably Perl/PREG style), which can be used to identify the URL from within a HTML link tag. Example: The regular _expression should match the tag &lt;A HREF="http://www.yoursite.com/" and give the URL ("http://www.yoursite.com/") as a return result. Tags should also be matched if they contain other attributes than the HREF attribute.&lt;br /&gt;Answer:&lt;br /&gt;$regexp = "/[http]+[0-9A-Za-z_:\/\.]+[^\"]/";&lt;br /&gt;$str = "&lt;a HREF=\"http://www.yoursite.com/\"";&lt;br /&gt;preg_match($regexp,$str,$arr);&lt;br /&gt;echo $arr[0];&lt;br /&gt;89. A select query over a large table runs very slow because of the growing number of entries in that table. What different measures could be taken to improve speed?&lt;br /&gt;Answer:&lt;br /&gt;In general, when you want to make a slow SELECT … WHERE query faster, the first thing to check is whether you can add an index. All references between different tables should usually be done with indexes. You can use the EXPLAIN statement to determine which indexes are used for a SELECT.&lt;br /&gt;Some general tips for speeding up queries on MyISAM tables:&lt;br /&gt;A: To help MySQL better optimize queries, use ANALYZE TABLE or run myisamchk --analyze on a table after it has been loaded with data. This updates a value for each index part that indicates the average number of rows that have the same value. (For unique indexes, this is always 1.) MySQL uses this to decide which index to choose when you join two tables based on a non-constant expression. You can check the result from the table analysis by using SHOW INDEX FROM tbl_name and examining the Cardinality value. myisamchk --description --verbose shows index distribution information.&lt;br /&gt;90. A company wants to store their invoices in a database. They already have their customers and articles in that database. Both customer and article are each identified by an unique integer value. Please create the SQL statements for creating the necessary table(s) for storing the invoices in a MySQL database. An invoice should hold information like invoice number, customer, date, article(s) and quantity etc.&lt;br /&gt;Ans:&lt;br /&gt;CREATE TABLE invoice (&lt;br /&gt;id int(11) NOT NULL default '0',&lt;br /&gt;invoceNo int(11) NOT NULL default '0',&lt;br /&gt;customer_id varchar(20) NOT NULL default '0',&lt;br /&gt;article_id varchar(20) NOT NULL default '0',&lt;br /&gt;date varchar(20) NOT NULL default '0',&lt;br /&gt;quantity int(11) NOT NULL default '0',&lt;br /&gt;PRIMARY KEY (id)&lt;br /&gt;) TYPE=MyISAM;&lt;br /&gt;91. For the database from the previous question, please give an SQL query which returns the invoice number of all invoices which contain the article with the number "1234". The query should be able to run under a MySQL 4.0 database.&lt;br /&gt;Answer:&lt;br /&gt;Select invoceNo from invoice where article_id=1234;&lt;br /&gt;92. How would you backup and restore a big MySQL database? What are the advantages of the approach which you have taken over the others?&lt;br /&gt;Use the mysqldump command.&lt;br /&gt;If you have Telnet/SSH access to your MySQL server, log in and issue the following command for each database you want to back up:&lt;br /&gt;shell&gt; mysqldump -u user -ppassword --opt -full database_name &gt; backupfile.sql&lt;br /&gt;Then move the resulting file(s) to your preferred backup areas. If you require more information on the mysqldump command, then simply check out this URL:www.mysql.com/documentation/mysql&lt;br /&gt;Copy all the relevant table files.&lt;br /&gt;If the server isn't updating anything (or you've deliberately killed mysqld for this purpose) then you can copy all the files with the following extensions in your MySQL data directory:&lt;br /&gt;*.frm&lt;br /&gt;*.myd&lt;br /&gt;*.myi&lt;br /&gt;Make sure you restart the MySQL daemon once you finish copying and downloading the files to your preferred backup areas.&lt;br /&gt;TIP: once you've completed the backup, restart MySQL with the --log-update switch. This will allow you to keep track of all modifications done in the MySQL tables since your last 'dump'.&lt;br /&gt;To restore your dumps, you should either restore to an existing database or create a new database using&lt;br /&gt;shell&gt; mysqladmin create database_name&lt;br /&gt;then issue the following command :&lt;br /&gt;shell&gt; mysql -u user -ppassword database_name &lt; backup-file.sql&lt;br /&gt;If you don't have access to Telnet/SSH and you're unable to do backups using the methods described above, you should ask your host if it is possible for them to do a backup for you and put the backups in a separate directory so that you can easily&lt;br /&gt;FTP your backups to your selected backup areas. Otherwise, if you have access to phpMyAdmin, you can use the following procedure:&lt;br /&gt;Access phpMyAdmin, and select the database you wish to 'dump' (backup).&lt;br /&gt;Scroll down and you will see a bulleted point saying: "View dump (schema) of database" along with some radio and check boxes. Choose 'Structure and data', then click on 'Add Drop Table' and 'Send' and click 'Go'. This will save the 'dump' to your hard drive.&lt;br /&gt;To restore a dump using phpMyAdmin, simply insert the file in the correct place once you have chosen the correct database by doing the following:&lt;br /&gt;Choose the database you will insert your data into, or create a new database.&lt;br /&gt;Insert the appropriate SQL queries you already have, or just paste the name of the .sql file you have on your hard drive into the text box under 'Location of the textfile', and fire away!&lt;br /&gt;Tip : use a crontab job to schedule backups periodically.&lt;br /&gt;The advantages of this approach is the backup is only a file consisting of SQL query. So that needs minimum spaces to backup a large database.&lt;br /&gt;93. Create a PHP web script with the following attributes: on start, three HTML form elements are shown: an string input field, a checkbox field, a dropdown/pull down list with 5 elements and a submit button. On submission, the form should be redisplayed (while remaining all options/inputs as the user has selected/entered them). Additionally,&lt;br /&gt;the selections/inputs of the user should be displayed in text. Please solve this without the use of any external libraries.&lt;br /&gt;Answer:&lt;br /&gt;Ans:&lt;br /&gt;&lt;?&lt;br /&gt;$name=$_POST['txtName']; //Value of text field&lt;br /&gt;$chkState=$_POST['chkState']; // Value of check box&lt;br /&gt;$sltItem=$_POST['sltItem']; // Value of the List box&lt;br /&gt;?&gt;&lt;br /&gt;&lt;form name="form1" method="post" action=""&gt;&lt;br /&gt;&lt;table width="100%" border="0"&gt;&lt;br /&gt;&lt;tr&gt;&lt;br /&gt;&lt;td&gt; &lt;input name="txtName" type="text" id="txtName" value="&lt;?"&gt;&gt;&lt;/td&gt;&lt;br /&gt;&lt;/tr&gt; &lt;tr&gt;&lt;br /&gt;&lt;td&gt;&lt;input name="chkState" type="checkbox" chkstate="="'on')"&gt; &gt;&lt;/td&gt;&lt;br /&gt;&lt;/tr&gt;&lt;tr&gt;&lt;br /&gt;&lt;td&gt;&lt;div align="right"&gt;&lt;/div&gt;&lt;br /&gt;&lt;select name="sltItem" id="sltItem"&gt;&lt;br /&gt;&lt;?&lt;br /&gt;$arr=array("BD","AU","USA","UK","JP"); //Array of the Items os list box&lt;br /&gt;for($i=0;$i&lt;5;$i++){ // 5 items are taken as sample&lt;br /&gt;if($sltItem==$i)&lt;br /&gt;echo" &lt;option value="$i"&gt;$arr[$i] &lt;/option&gt;";&lt;br /&gt;else&lt;br /&gt;echo" &lt;option value="$i"&gt;$arr[$i] &lt;/option&gt;";&lt;br /&gt;}&lt;br /&gt;?&gt;&lt;br /&gt;&lt;/select&gt;&lt;/td&gt;&lt;br /&gt;&lt;/tr&gt;&lt;tr&gt;&lt;br /&gt;&lt;td&gt;&lt;input type="submit" name="Submit" value="Submit"&gt; &lt;/td&gt;&lt;br /&gt;&lt;/tr&gt; &lt;/table&gt;&lt;br /&gt;&lt;/form&gt;&lt;br /&gt;94. What is meant by MIME?&lt;br /&gt;Answer:&lt;br /&gt;Multipurpose Internet Mail Extensions.&lt;br /&gt;WWW's ability to recognise and handle files of different types is largely dependent on the use of the MIME (Multipurpose Internet Mail Extensions) standard. The standard provides for a system of registration of file types with information about the applications needed to process them. This information is incorporated into Web server and browser software, and enables the automatic recognition and display of registered file types. ...&lt;br /&gt;95. What is meant by PEAR in php?&lt;br /&gt;Answer:&lt;br /&gt;PEAR is short for “PHP Extension and Application Repository” and is pronounced just like the fruit. The purpose of PEAR is to provide:&lt;br /&gt;A structured library of open-sourced code for PHP users&lt;br /&gt;A system for code distribution and package maintenance&lt;br /&gt;A standard style for code written in PHP&lt;br /&gt;The PHP Foundation Classes (PFC),&lt;br /&gt;The PHP Extension Community Library (PECL),&lt;br /&gt;A web site, mailing lists and download mirrors to support the PHP/PEAR community&lt;br /&gt;PEAR is a community-driven project with the PEAR Group as the governing body. The project has been founded by Stig S. Bakken in 1999 and quite a lot of people have joined the project since then.&lt;br /&gt;http://pear.php.net/manual/en/introduction.php&lt;br /&gt;96. How can I use the COM components in php?&lt;br /&gt;Answer:&lt;br /&gt;The COM class provides a framework to integrate (D)COM components into your PHP scripts.&lt;br /&gt;string COM::COM ( string module_name [, string server_name [, int codepage]])&lt;br /&gt;COM class constructor. Parameters:&lt;br /&gt;module_name&lt;br /&gt;name or class-id of the requested component.&lt;br /&gt;server_name&lt;br /&gt;name of the DCOM server from which the component should be fetched. If NULL, localhost is assumed. To allow DCOM com.allow_dcom has to be set to TRUE in php.ini.&lt;br /&gt;codepage&lt;br /&gt;specifies the codepage that is used to convert php-strings to unicode-strings and vice versa. Possible values are CP_ACP, CP_MACCP, CP_OEMCP, CP_SYMBOL, CP_THREAD_ACP, CP_UTF7 and CP_UTF8.&lt;br /&gt;Usage:&lt;br /&gt;&lt;?php // starting word $word = new COM("word.application") or die("Unable to instanciate Word"); echo "Loaded Word, version {$word-&gt;Version}\n"; //bring it to front $word-&gt;Visible = 1; //open an empty document $word-&gt;Documents-&gt;Add(); //do some weird stuff $word-&gt;Selection-&gt;TypeText("This is a test..."); $word-&gt;Documents[1]-&gt;SaveAs("Useless test.doc"); //closing word $word-&gt;Quit(); //free the object $word-&gt;Release(); $word = null; ?&gt;&lt;br /&gt;97. How can I load the dllâ€™s dynamically?&lt;br /&gt;98. How many ways we can give the output to a browser?&lt;br /&gt;Answer:&lt;br /&gt;HTML output&lt;br /&gt;PHP, ASP, JSP, Servlet Function&lt;br /&gt;Script Language output Function&lt;br /&gt;Different Type of embedded Package to output to a browser&lt;br /&gt;99. How can we know that a session is started or not?&lt;br /&gt;Answer:&lt;br /&gt;a session starts by session_start()function.&lt;br /&gt;this session_start() is always declared in header portion.it always declares first.then we write session_register().&lt;br /&gt;100. What is the default session time in php and how can I change it?&lt;br /&gt;Answer:&lt;br /&gt;The default session time in php is until closing of browser&lt;br /&gt;101. What changes I have to done in php.ini file for file uploading?&lt;br /&gt;Answer:&lt;br /&gt;Make the following Line uncomment like:&lt;br /&gt;; Whether to allow HTTP file uploads.&lt;br /&gt;file_uploads = On&lt;br /&gt;; Temporary directory for HTTP uploaded files (will use system default if not&lt;br /&gt;; specified).&lt;br /&gt;upload_tmp_dir = C:\apache2triad\temp&lt;br /&gt;; Maximum allowed size for uploaded files.&lt;br /&gt;upload_max_filesize = 2M&lt;br /&gt;102. What are the differences between mysql_fetch_array(), mysql_fetch_object(), mysql_fetch_row()?&lt;br /&gt;Answer:&lt;br /&gt;mysql_fetch_array -- Fetch a result row as an associative array, a numeric array, or both.&lt;br /&gt;mysql_fetch_object ( resource result )&lt;br /&gt;Returns an object with properties that correspond to the fetched row and moves the internal data pointer ahead. Returns an object with properties that correspond to the fetched row, or FALSE if there are no more rows&lt;br /&gt;mysql_fetch_row() fetches one row of data from the result associated with the specified result identifier. The row is returned as an array. Each result column is stored in an array offset, starting at offset 0.&lt;br /&gt;103. How can I set a cron and how can I execute it in Unix, Linux, and windows?&lt;br /&gt;Answer:&lt;br /&gt;Cron is very simply a Linux module that allows you to run commands at predetermined times or intervals. In Windows, it’s called Scheduled Tasks. The name Cron is in fact derived from the same word from which we get the word chronology, which means order of time.&lt;br /&gt;The easiest way to use crontab is via the crontab command.&lt;br /&gt;# crontab –e&lt;br /&gt;This command ‘edits’ the crontab. Upon employing this command, you will be able to enter the commands that you wish to run. My version of Linux uses the text editor vi. You can find information on using vi here.&lt;br /&gt;The syntax of this file is very important – if you get it wrong, your crontab will not function properly. The syntax of the file should be as follows:&lt;br /&gt;minutes hours day_of_month month day_of_week command&lt;br /&gt;All the variables, with the exception of the command itself, are numerical constants. In addition to an asterisk (*), which is a wildcard that allows any value, the ranges permitted for each field are as follows:&lt;br /&gt;Minutes: 0-59&lt;br /&gt;Hours: 0-23&lt;br /&gt;Day_of_month: 1-31&lt;br /&gt;Month: 1-12&lt;br /&gt;Weekday: 0-6&lt;br /&gt;We can also include multiple values for each entry, simply by separating each value with a comma.&lt;br /&gt;command can be any shell command and, as we will see momentarily, can also be used to execute a Web document such as a PHP file.&lt;br /&gt;So, if we want to run a script every Tuesday morning at 8:15 AM, our mycronjob file will contain the following content on a single line:&lt;br /&gt;15 8 * * 2 /path/to/scriptname&lt;br /&gt;This all seems simple enough, right? Not so fast! If you try to run a PHP script in this manner, nothing will happen (barring very special configurations that have PHP compiled as an executable, as opposed to an Apache module). The reason is that, in order for PHP to be parsed, it needs to be passed through Apache. In other words, the page needs to be called via a browser or other means of retrieving Web content.&lt;br /&gt;For our purposes, I’ll assume that your server configuration includes wget, as is the case with most default configurations. To test your configuration, log in to shell. If you’re using an RPM-based system (e.g. Redhat or Mandrake), type the following:&lt;br /&gt;# wget --help&lt;br /&gt;If you are greeted with a wget package identification, it is installed in your system.&lt;br /&gt;You could execute the PHP by invoking wget on the URL to the page, like so:&lt;br /&gt;# wget http://www.example.com/file.php&lt;br /&gt;Now, let’s go back to the mailstock.php file we created in the first part of this article. We saved it in our document root, so it should be accessible via the Internet. Remember that we wanted it to run at 4PM Eastern time, and send you your precious closing bell report? Since I’m located in the Eastern timezone, we can go ahead and set up our crontab to use 4:00, but if you live elsewhere, you might have to compensate for the time difference when setting this value.&lt;br /&gt;This is what my crontab will look like:&lt;br /&gt;0 4 * * 1,2,3,4,5 wget http://www.example.com/mailstock.php&lt;br /&gt;104. Steps for the payment gateway processing?&lt;br /&gt;Ans:&lt;br /&gt;An online payment gateway is the interface between your merchant account and your Web site. The online payment gateway allows you to immediately verify credit card transactions and authorize funds on a customer's credit card directly from your Web site. It then passes the transaction off to your merchant bank for processing, commonly referred to as transaction batching&lt;br /&gt;105. How many ways I can register the variables into session?&lt;br /&gt;Answer:&lt;br /&gt;session_register(); $_SESSION[]; $HTTP_SESSION_VARS[];&lt;br /&gt;106. Explain different types of errors in php (i.e. arguments in error reporting function)?&lt;br /&gt;Answer:&lt;br /&gt;Three are three types of errors:&lt;br /&gt;1. Notices: These are trivial, non-critical errors that PHP encounters while executing a script - for example, accessing a variable that has not yet been defined. By default, such errors are not displayed to the user at all - although, as you will see, you can change this default behaviour.&lt;br /&gt;2. Warnings: These are more serious errors - for example, attempting to include() a file which does not exist. By default, these errors are displayed to the user, but they do not result in script termination.&lt;br /&gt;3. Fatal errors: These are critical errors - for example, instantiating an object of a non-existent class, or calling a non-existent function. These errors cause the immediate termination of the script, and PHP's default behaviour is to display them to the user when they take place.&lt;br /&gt;107. How many ways I can redirect a php page?&lt;br /&gt;Answer;&lt;br /&gt;Here are the possible ways of php page redirection.&lt;br /&gt;Using Java script:&lt;br /&gt;&lt;?php function redirect($filename) { if (!headers_sent()) header('Location: '.$filename); else { echo '&lt;script type="text/javascript"&gt;'; echo 'window.location.href="'.$filename.'";'; echo '&lt;/script&gt;'; echo '&lt;noscript&gt;'; echo '&lt;meta equiv="refresh" content="0;url='.$filename.'"&gt;'; echo '&lt;/noscript&gt;'; } } redirect('http://maosjb.com'); ?&gt;&lt;br /&gt;Using php function:&lt;br /&gt;Header("Location:http://maosjb.com ");&lt;br /&gt;108. List out different arguments in php header function?&lt;br /&gt;Answer:&lt;br /&gt;void header ( string string [, bool replace [, int http_response_code]])&lt;br /&gt;109. What type of headers have to add in the mail function in which file a attached?&lt;br /&gt;Answer:&lt;br /&gt;$boundary = '-----=' . md5( uniqid ( rand() ) );&lt;br /&gt;$headers = "From: \"Me\"&lt;me@here.com&gt;\n";&lt;br /&gt;$headers .= "MIME-Version: 1.0\n";&lt;br /&gt;$headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"";&lt;br /&gt;110. What is the difference between &lt;?php ?&gt; and &lt;? ?&gt; And which can be&lt;br /&gt;preferable?&lt;br /&gt;Answer:&lt;br /&gt;If functionality is same but &lt;? Is the short tag of &lt;?php. Using short tags should be avoided when developing applications or libraries that are meant for redistribution, or deployment on PHP servers, which are not under your control, because short tags may not be supported on the target server. For portable, redistributable code, be sure not to use short tags.&lt;br /&gt;111. What are the differences between php3 and php4 versions?&lt;br /&gt;&lt;br /&gt;Answer:&lt;br /&gt;As has already been mentioned by many PHP4 has native support for sessions&lt;br /&gt;and the much touted XML. While this makes PHP a competitor in the&lt;br /&gt;Application server languages arena, there is another core aspect to PHP4. It&lt;br /&gt;is faster.&lt;br /&gt;PHP3 used to parse line by line, while PHP acts like a compiler. This along&lt;br /&gt;with the ZEND optimizer makes PHP4 almost always faster than PHP3.&lt;br /&gt;I'm not sure about support for COM, it has caught my attention only in PHP4.&lt;br /&gt;If it was present in PHP3 I was not aware of it.&lt;br /&gt;Plus PHP4 can run as an Apache module, again this could have come in the&lt;br /&gt;late versions of PHP3.&lt;br /&gt;112. What are the differences between include() and include_once()&lt;br /&gt;functions?&lt;br /&gt;Answer: include_once() will use the specified file only once. include and require will use the specified file as many time we want. If include_once() is used before with same name, it can not done again&lt;br /&gt;113. Describe the importance of DATA BASE ABSTRACTION LAYERS in php&lt;br /&gt;and database connection?&lt;br /&gt;Answer:&lt;br /&gt;Please visit to know about Database abstraction layers&lt;br /&gt;http://www.oracle.com/technology/pub/articles/deployphp/schlitt_deployphp.html&lt;br /&gt;114. Explain mysql optimization?&lt;br /&gt;Answer:&lt;br /&gt;Optimization is a complex task because ultimately it requires understanding of the entire system. Although it may be possible to perform some local optimizations with little knowledge of your system or application, the more optimal you want your system to become, the more you will have to know about it. The most important factor in making a system fast is the basic design. You also need to know what kinds of things your system will be doing, and what your bottlenecks are.&lt;br /&gt;See more at: http://www.serveriai.lt/manual/mysql/manual_MySQL_Optimisation.html&lt;br /&gt;115. What is the difference between using copy() and move() function&lt;br /&gt;in php file uploading?&lt;br /&gt;copy ( string source, string dest)&lt;br /&gt;Makes a copy of the file source to dest. Returns TRUE on success or FALSE on failure. Usage: &lt;?php if (!copy($file, $file.'.bak')) { echo "failed to copy $file...&lt;br /&gt;\n"; } ?&gt;&lt;br /&gt;move_uploaded_file ( string filename, string destination)&lt;br /&gt;This function checks to ensure that the file designated by filename is a valid upload file (meaning that it was uploaded via PHP's HTTP POST upload mechanism). If the file is valid, it will be moved to the filename given by destination.&lt;br /&gt;If filename is not a valid upload file, then no action will occur, and move_uploaded_file() will return FALSE.&lt;br /&gt;If filename is a valid upload file, but cannot be moved for some reason, no action will occur, and move_uploaded_file() will return FALSE. Additionally, a warning will be issued.&lt;br /&gt;116. What is the difference between Reply-to and Return-path in the headers of a mail function?&lt;br /&gt;Answer:&lt;br /&gt;Reply-to: Reply-to is where to delivery the reply of the mail.&lt;br /&gt;Return-path: Return path is when there is a mail delivery failure occurs then where to delivery the failure notification.&lt;br /&gt;117. Explain about Type Juggling in php?&lt;br /&gt;Answer:&lt;br /&gt;PHP does not require (or support) explicit type definition in variable declaration; a variable's type is determined by the context in which that variable is used. That is to say, if you assign a string value to variable $var, $var becomes a string. If you then assign an integer value to $var, it becomes an integer.&lt;br /&gt;An example of PHP's automatic type conversion is the addition operator '+'. If any of the operands is a float, then all operands are evaluated as floats, and the result will be a float. Otherwise, the operands will be interpreted as integers, and the result will also be an integer. Note that this does NOT change the types of the operands themselves; the only change is in how the operands are evaluated.&lt;br /&gt;&lt;?php&lt;br /&gt;$foo = "0"; // $foo is string (ASCII 48)&lt;br /&gt;&lt;!-- bad example, no real operator (must be used with variable, modifies it too)&lt;br /&gt;$foo++; // $foo is the string "1" (ASCII 49)&lt;br /&gt;--&gt;&lt;br /&gt;$foo += 2; // $foo is now an integer (2)&lt;br /&gt;$foo = $foo + 1.3; // $foo is now a float (3.3)&lt;br /&gt;$foo = 5 + "10 Little Piggies"; // $foo is integer (15)&lt;br /&gt;$foo = 5 + "10 Small Pigs"; // $foo is integer (15)&lt;br /&gt;&lt;!--&lt;br /&gt;TODO: explain ++/- - behaviour with strings&lt;br /&gt;examples:&lt;br /&gt;++'001' = '002'&lt;br /&gt;++'abc' = 'abd'&lt;br /&gt;++'xyz' = 'xza'&lt;br /&gt;++'9.9' = '9.0'&lt;br /&gt;++'-3' = '-4'&lt;br /&gt;- -'9' = 8 (integer!)&lt;br /&gt;- -'5.5' = '5.5'&lt;br /&gt;- -'-9' = -10 (integer)&lt;br /&gt;- -'09' = 8 (integer)&lt;br /&gt;- -'abc' = 'abc'&lt;br /&gt;--&gt;&lt;br /&gt;?&gt;&lt;br /&gt;If the last two examples above seem odd, see String conversion to numbers.&lt;br /&gt;If you wish to change the type of a variable, see settype().&lt;br /&gt;If you would like to test any of the examples in this section, you can use the var_dump() function.&lt;br /&gt;Note: The behavior of an automatic conversion to array is currently undefined.&lt;br /&gt;&lt;?php&lt;br /&gt;$a = "1"; // $a is a string&lt;br /&gt;$a[0] = "f"; // What about string offsets? What happens?&lt;br /&gt;?&gt;&lt;br /&gt;Since PHP (for historical reasons) supports indexing into strings via offsets using the same syntax as array indexing, the example above leads to a problem: should $a become an array with its first element being "f", or should "f" become the first character of the string $a?&lt;br /&gt;The current versions of PHP interpret the second assignment as a string offset identification, so $a becomes "f", the result of this automatic conversion however should be considered undefined. PHP 4 introduced the new curly bracket syntax to access characters in string, use this syntax instead of the one presented above:&lt;br /&gt;&lt;?php&lt;br /&gt;$a = "abc"; // $a is a string&lt;br /&gt;$a{1} = "f"; // $a is now "afc"&lt;br /&gt;?&gt;&lt;br /&gt;118. How can I get the only name of the current executing file?&lt;br /&gt;&lt;?php&lt;br /&gt;$curfilename = __FILE__; //current file name with full path&lt;br /&gt;$pieces = explode("\\", $curfilename);&lt;br /&gt;$onlyfilenamewithext = $pieces[count($pieces)-1]; //current file name with extension only&lt;br /&gt;$temp = explode(".",$onlyfilenamewithext);&lt;br /&gt;$onlyfilename = $temp[0]; //current file name without extension&lt;br /&gt;echo $onlyfilename;&lt;br /&gt;?&gt;&lt;br /&gt;119. How can I embed a java programme in php file and what changes&lt;br /&gt;have to be done in php.ini file?&lt;br /&gt;There are two possible ways to bridge PHP and Java: you can either integrate PHP into a Java Servlet environment, which is the more stable and efficient solution, or integrate Java support into PHP. The former is provided by a SAPI module that interfaces with the Servlet server, the latter by this Java extension.&lt;br /&gt;The Java extension provides a simple and effective means for creating and invoking methods on Java objects from PHP. The JVM is created using JNI, and everything runs in-process.&lt;br /&gt;Example Code:&lt;br /&gt;&lt;?php // get instance of Java class java.lang.System in PHP $system = new Java('java.lang.System'); // demonstrate property access echo 'Java version=' . $system-&gt;getProperty('java.version') . '&lt;br /&gt;'; echo 'Java vendor=' . $system-&gt;getProperty('java.vendor') . '&lt;br /&gt;'; echo 'OS=' . $system-&gt;getProperty('os.name') . ' ' . $system-&gt;getProperty('os.version') . ' on ' . $system-&gt;getProperty('os.arch') . ' &lt;br /&gt;'; // java.util.Date example $formatter = new Java('java.text.SimpleDateFormat', "EEEE, MMMM dd, yyyy 'at' h:mm:ss a zzzz"); echo $formatter-&gt;format(new Java('java.util.Date')); ?&gt;&lt;br /&gt;The behaviour of these functions is affected by settings in php.ini.&lt;br /&gt;Table 1. Java configuration options&lt;br /&gt;Name&lt;br /&gt;Default&lt;br /&gt;Changeable&lt;br /&gt;java.class.path&lt;br /&gt;NULL&lt;br /&gt;PHP_INI_ALL&lt;br /&gt;Name Default Changeable&lt;br /&gt;java.home&lt;br /&gt;NULL&lt;br /&gt;PHP_INI_ALL&lt;br /&gt;java.library.path&lt;br /&gt;NULL&lt;br /&gt;PHP_INI_ALL&lt;br /&gt;java.library&lt;br /&gt;JAVALIB&lt;br /&gt;PHP_INI_ALL&lt;br /&gt;120. How can I find what type of images that the php version supports?&lt;br /&gt;Answer:&lt;br /&gt;Using Imagetypes() function we can know&lt;br /&gt;Usage:&lt;br /&gt;&lt;?php if (imagetypes() &amp;amp; IMG_PNG) { echo "PNG Support is enabled"; } ?&gt;&lt;br /&gt;121. The table tbl_sites contains the following data.&lt;br /&gt;-----------------------------------------------------&lt;br /&gt;Userid sitename country&lt;br /&gt;------------------------------------------------------&lt;br /&gt;1 sureshbabu indian&lt;br /&gt;2 phpprogrammer andhra&lt;br /&gt;3 php.net usa&lt;br /&gt;4 phptalk.com germany&lt;br /&gt;5 mysql.com usa&lt;br /&gt;6 sureshbabu canada&lt;br /&gt;7 phpbuddy.com pakistan&lt;br /&gt;8. phptalk.com austria&lt;br /&gt;9. phpfreaks.com sourthafrica&lt;br /&gt;10. phpsupport.net russia&lt;br /&gt;11. sureshbabu australia&lt;br /&gt;12. sureshbabu nepal&lt;br /&gt;13. phptalk.com italy&lt;br /&gt;Write a select query that will displayed the duplicated site name&lt;br /&gt;and how many times it is duplicated?&lt;br /&gt;Answer: SELECT sitename,&lt;br /&gt;COUNT(sitename) AS NumOccurrences&lt;br /&gt;FROM tbl_sites&lt;br /&gt;GROUP BY sitemail&lt;br /&gt;HAVING ( COUNT(sitemail) &gt; 1 )&lt;br /&gt;Or&lt;br /&gt;SELECT sitename&lt;br /&gt;FROM tbl_sites&lt;br /&gt;GROUP BY sitename&lt;br /&gt;HAVING ( COUNT(sitename) = 1 )&lt;br /&gt;122. How can we send mail using JavaScript?&lt;br /&gt;Answer:&lt;br /&gt;No. You can't send mail using Javascript. But you can execute a client side email client to send the email using mailto: code.&lt;br /&gt;Using clientside email client&lt;br /&gt;function myfunction(form)&lt;br /&gt;{&lt;br /&gt;tdata=document.myform.tbox1.value;&lt;br /&gt;location="mailto:mailid@domain.com?subject="+tdata+"/MYFORM";&lt;br /&gt;return true; }&lt;br /&gt;Sources :&lt;br /&gt;DEVFYI - Developer Resource - FYI&lt;br /&gt;TechGuider - techguider&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2938427049868690639-4677779726764811835?l=scriptingfaqs.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://scriptingfaqs.blogspot.com/feeds/4677779726764811835/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2938427049868690639&amp;postID=4677779726764811835' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2938427049868690639/posts/default/4677779726764811835'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2938427049868690639/posts/default/4677779726764811835'/><link rel='alternate' type='text/html' href='http://scriptingfaqs.blogspot.com/2008/07/php-interview-question-answer.html' title='PHP Interview Question &amp; Answer'/><author><name>Siebel Expert</name><uri>http://www.blogger.com/profile/11533458660230230361</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2938427049868690639.post-1597894701576922620</id><published>2008-07-04T08:35:00.000-07:00</published><updated>2008-12-23T03:54:08.335-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='PHP'/><category scheme='http://www.blogger.com/atom/ns#' term='Scripting Language'/><title type='text'>PHP Interview Questions And Answers</title><content type='html'>What's PHP&lt;br /&gt;The PHP Hypertext Preprocessor is a programming language that allows web developers to create dynamic content that interacts with databases. PHP is basically used for developing web based software applications.&lt;br /&gt;&lt;br /&gt;What Is a Session?&lt;br /&gt;A session is a logical object created by the PHP engine to allow you to preserve data across subsequent HTTP requests.&lt;br /&gt;There is only one session object available to your PHP scripts at any time. Data saved to the session by a script can be retrieved by the same script or another script when requested from the same visitor.&lt;br /&gt;Sessions are commonly used to store temporary data to allow multiple PHP pages to offer a complete functional transaction for the same visitor.&lt;br /&gt;&lt;br /&gt;What is meant by PEAR in php?&lt;br /&gt;Answer1:&lt;br /&gt;PEAR is the next revolution in PHP. This repository is bringing higher level programming to PHP. PEAR is a framework and distribution system for reusable PHP components. It eases installation by bringing an automated wizard, and packing the strength and experience of PHP users into a nicely organised OOP library. PEAR also provides a command-line interface that can be used to automatically install "packages"&lt;br /&gt;&lt;br /&gt;Answer2:&lt;br /&gt;PEAR is short for "PHP Extension and Application Repository" and is pronounced just like the fruit. The purpose of PEAR is to provide:&lt;br /&gt;A structured library of open-sourced code for PHP users&lt;br /&gt;A system for code distribution and package maintenance&lt;br /&gt;A standard style for code written in PHP&lt;br /&gt;The PHP Foundation Classes (PFC),&lt;br /&gt;The PHP Extension Community Library (PECL),&lt;br /&gt;A web site, mailing lists and download mirrors to support the PHP/PEAR community&lt;br /&gt;PEAR is a community-driven project with the PEAR Group as the governing body. The project has been founded by Stig S. Bakken in 1999 and quite a lot of people have joined the project since then.&lt;br /&gt;&lt;br /&gt;How can we know the number of days between two given dates using PHP?&lt;br /&gt;Simple arithmetic:&lt;br /&gt;&lt;br /&gt;$date1 = date('Y-m-d');&lt;br /&gt;$date2 = '2006-07-01';&lt;br /&gt;$days = (strtotime() - strtotime()) / (60 * 60 * 24);&lt;br /&gt;echo "Number of days since '2006-07-01': $days";&lt;br /&gt;&lt;br /&gt;How can we repair a MySQL table?&lt;br /&gt;The syntex for repairing a mysql table is:&lt;br /&gt;&lt;br /&gt;REPAIR TABLE tablename&lt;br /&gt;REPAIR TABLE tablename QUICK&lt;br /&gt;REPAIR TABLE tablename EXTENDED&lt;br /&gt;&lt;br /&gt;This command will repair the table specified.&lt;br /&gt;If QUICK is given, MySQL will do a repair of only the index tree.&lt;br /&gt;If EXTENDED is given, it will create index row by row.&lt;br /&gt;&lt;br /&gt;What is the difference between $message and $$message?&lt;br /&gt;Anwser 1:&lt;br /&gt;$message is a simple variable whereas $$message is a reference variable. Example:&lt;br /&gt;$user = 'bob'&lt;br /&gt;&lt;br /&gt;is equivalent to&lt;br /&gt;&lt;br /&gt;$holder = 'user';&lt;br /&gt;$$holder = 'bob';&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Anwser 2:&lt;br /&gt;They are both variables. But $message is a variable with a fixed name. $$message is a variable who's name is stored in $message. For example, if $message contains "var", $$message is the same as $var.&lt;br /&gt;&lt;br /&gt;What Is a Persistent Cookie?&lt;br /&gt;A persistent cookie is a cookie which is stored in a cookie file permanently on the browser's computer. By default, cookies are created as temporary cookies which stored only in the browser's memory. When the browser is closed, temporary cookies will be erased. You should decide when to use temporary cookies and when to use persistent cookies based on their differences:&lt;br /&gt; Temporary cookies can not be used for tracking long-term information.&lt;br /&gt; Persistent cookies can be used for tracking long-term information.&lt;br /&gt; Temporary cookies are safer because no programs other than the browser can access them.&lt;br /&gt;&lt;br /&gt; Persistent cookies are less secure because users can open cookie files see the cookie values.&lt;br /&gt;&lt;br /&gt;What does a special set of tags &lt;?= and ?&gt; do in PHP?&lt;br /&gt;The output is displayed directly to the browser.&lt;br /&gt;&lt;br /&gt;How do you define a constant?&lt;br /&gt;Via define() directive, like define ("MYCONSTANT", 100);&lt;br /&gt;How To Write the FORM Tag Correctly for Uploading Files?&lt;br /&gt;When users clicks the submit button, files specified in the &lt;input type="FILE..."&gt; will be transferred from the browser to the Web server. This transferring (uploading) process is controlled by a properly written &lt;form...&gt; tag as:&lt;br /&gt;  &lt;form action="receiving.php" method="post" enctype="multipart/form-data"&gt;&lt;br /&gt;Note that you must specify METHOD as "post" and ENCTYPE as "multipart/form-data" in order for the uploading process to work. The following PHP code, called logo_upload.php, shows you a complete FORM tag for file uploading:&lt;br /&gt;&lt;?php&lt;br /&gt;  print("&lt;html&gt;&lt;form action=processing_uploaded_files.php"&lt;br /&gt;    ." method=post enctype=multipart/form-data&gt;\n");&lt;br /&gt;  print("Please submit an image file a Web site logo for"&lt;br /&gt;    ." fyicenter.com:&lt;br /&gt;\n");&lt;br /&gt;  print("&lt;input type="file" name="fyicenter_logo"&gt;&lt;br /&gt;\n");&lt;br /&gt;  print("&lt;input type="submit"&gt;\n");&lt;br /&gt;  print("&lt;/form&gt;&lt;/html&gt;\n");&lt;br /&gt;?&gt;&lt;br /&gt;&lt;br /&gt;What are the differences between require and include, include_once?&lt;br /&gt;Anwser 1:&lt;br /&gt;require_once() and include_once() are both the functions to include and evaluate the specified file only once. If the specified file is included previous to the present call occurrence, it will not be done again.&lt;br /&gt;&lt;br /&gt;But require() and include() will do it as many times they are asked to do.&lt;br /&gt;&lt;br /&gt;Anwser 2:&lt;br /&gt;The include_once() statement includes and evaluates the specified file during the execution of the script. This is a behavior similar to the include() statement, with the only difference being that if the code from a file has already been included, it will not be included again. The major difference between include() and require() is that in failure include() produces a warning message whereas require() produces a fatal errors.&lt;br /&gt;&lt;br /&gt;Anwser 3:&lt;br /&gt;All three are used to an include file into the current page.&lt;br /&gt;If the file is not present, require(), calls a fatal error, while in include() does not.&lt;br /&gt;The include_once() statement includes and evaluates the specified file during the execution of the script. This is a behavior similar to the include() statement, with the only difference being that if the code from a file has already been included, it will not be included again. It des not call a fatal error if file not exists. require_once() does the same as include_once(), but it calls a fatal error if file not exists.&lt;br /&gt;&lt;br /&gt;Anwser 4:&lt;br /&gt;File will not be included more than once. If we want to include a file once only and further calling of the file will be ignored then we have to use the PHP function include_once(). This will prevent problems with function redefinitions, variable value reassignments, etc.&lt;br /&gt;&lt;br /&gt;What is meant by urlencode and urldecode?&lt;br /&gt;Anwser 1:&lt;br /&gt;urlencode() returns the URL encoded version of the given string. URL coding converts special characters into % signs followed by two hex digits. For example: urlencode("10.00%") will return "10%2E00%25". URL encoded strings are safe to be used as part of URLs.&lt;br /&gt;urldecode() returns the URL decoded version of the given string.&lt;br /&gt;&lt;br /&gt;Anwser 2:&lt;br /&gt;string urlencode(str) - Returns the URL encoded version of the input string. String values to be used in URL query string need to be URL encoded. In the URL encoded version:&lt;br /&gt;&lt;br /&gt;Alphanumeric characters are maintained as is.&lt;br /&gt;Space characters are converted to "+" characters.&lt;br /&gt;Other non-alphanumeric characters are converted "%" followed by two hex digits representing the converted character.&lt;br /&gt;&lt;br /&gt;string urldecode(str) - Returns the original string of the input URL encoded string.&lt;br /&gt;&lt;br /&gt;For example:&lt;br /&gt;&lt;br /&gt;$discount ="10.00%";&lt;br /&gt;$url = "http://domain.com/submit.php?disc=".urlencode($discount);&lt;br /&gt;echo $url;&lt;br /&gt;&lt;br /&gt;You will get "http://domain.com/submit.php?disc=10%2E00%25".&lt;br /&gt;&lt;br /&gt;How To Get the Uploaded File Information in the Receiving Script?&lt;br /&gt;Once the Web server received the uploaded file, it will call the PHP script specified in the form action attribute to process them. This receiving PHP script can get the uploaded file information through the predefined array called $_FILES. Uploaded file information is organized in $_FILES as a two-dimensional array as:&lt;br /&gt; $_FILES[$fieldName]['name'] - The Original file name on the browser system.&lt;br /&gt; $_FILES[$fieldName]['type'] - The file type determined by the browser.&lt;br /&gt; $_FILES[$fieldName]['size'] - The Number of bytes of the file content.&lt;br /&gt; $_FILES[$fieldName]['tmp_name'] - The temporary filename of the file in which the uploaded file was stored on the server.&lt;br /&gt; $_FILES[$fieldName]['error'] - The error code associated with this file upload.&lt;br /&gt;The $fieldName is the name used in the &lt;input type="FILE," name="fieldName"&gt;.&lt;br /&gt;&lt;br /&gt;What is the difference between mysql_fetch_object and mysql_fetch_array?&lt;br /&gt;MySQL fetch object will collect first single matching record where mysql_fetch_array will collect all matching records from the table in an array&lt;br /&gt;&lt;br /&gt;How can I execute a PHP script using command line?&lt;br /&gt;Just run the PHP CLI (Command Line Interface) program and provide the PHP script file name as the command line argument. For example, "php myScript.php", assuming "php" is the command to invoke the CLI program.&lt;br /&gt;Be aware that if your PHP script was written for the Web CGI interface, it may not execute properly in command line environment.&lt;br /&gt;&lt;br /&gt;I am trying to assign a variable the value of 0123, but it keeps coming up with a different number, what’s the problem?&lt;br /&gt;PHP Interpreter treats numbers beginning with 0 as octal. Look at the similar PHP interview questions for more numeric problems.&lt;br /&gt;&lt;br /&gt;Would I use print "$a dollars" or "{$a} dollars" to print out the amount of dollars in this example?&lt;br /&gt;In this example it wouldn’t matter, since the variable is all by itself, but if you were to print something like "{$a},000,000 mln dollars", then you definitely need to use the braces.&lt;br /&gt;&lt;br /&gt;What are the different tables present in MySQL? Which type of table is generated when we are creating a table in the following syntax: create table employee(eno int(2),ename varchar(10))?&lt;br /&gt;Total 5 types of tables we can create&lt;br /&gt;1. MyISAM&lt;br /&gt;2. Heap&lt;br /&gt;3. Merge&lt;br /&gt;4. INNO DB&lt;br /&gt;5. ISAM&lt;br /&gt;MyISAM is the default storage engine as of MySQL 3.23. When you fire the above create query MySQL will create a MyISAM table.&lt;br /&gt;&lt;br /&gt;How To Create a Table?&lt;br /&gt;If you want to create a table, you can run the CREATE TABLE statement as shown in the following sample script:&lt;br /&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;include "mysql_connection.php";&lt;br /&gt;&lt;br /&gt;$sql = "CREATE TABLE fyi_links ("&lt;br /&gt;. " id INTEGER NOT NULL"&lt;br /&gt;. ", url VARCHAR(80) NOT NULL"&lt;br /&gt;. ", notes VARCHAR(1024)"&lt;br /&gt;. ", counts INTEGER"&lt;br /&gt;. ", time TIMESTAMP DEFAULT sysdate()"&lt;br /&gt;. ")";&lt;br /&gt;if (mysql_query($sql, $con)) {&lt;br /&gt;print("Table fyi_links created.\n");&lt;br /&gt;} else {&lt;br /&gt;print("Table creation failed.\n");&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;mysql_close($con);&lt;br /&gt;?&gt;&lt;br /&gt;&lt;br /&gt;Remember that mysql_query() returns TRUE/FALSE on CREATE statements. If you run this script, you will get something like this:&lt;br /&gt;Table fyi_links created.&lt;br /&gt;&lt;br /&gt;How can we encrypt the username and password using PHP?&lt;br /&gt;Answer1&lt;br /&gt;You can encrypt a password with the following Mysql&gt;SET PASSWORD=PASSWORD("Password");&lt;br /&gt;&lt;br /&gt;Answer2&lt;br /&gt;You can use the MySQL PASSWORD() function to encrypt username and password. For example,&lt;br /&gt;INSERT into user (password, ...) VALUES (PASSWORD($password”)), ...);&lt;br /&gt;&lt;br /&gt;How do you pass a variable by value?&lt;br /&gt;Just like in C++, put an ampersand in front of it, like $a = &amp;amp;$b&lt;br /&gt;&lt;br /&gt;WHAT IS THE FUNCTIONALITY OF THE FUNCTIONS STRSTR() AND STRISTR()?&lt;br /&gt;string strstr ( string haystack, string needle ) returns part of haystack string from the first occurrence of needle to the end of haystack. This function is case-sensitive.&lt;br /&gt;&lt;br /&gt;stristr() is idential to strstr() except that it is case insensitive.&lt;br /&gt;&lt;br /&gt;When are you supposed to use endif to end the conditional statement?&lt;br /&gt;When the original if was followed by : and then the code block without braces.&lt;br /&gt;&lt;br /&gt;How can we send mail using JavaScript?&lt;br /&gt;No. There is no way to send emails directly using JavaScript.&lt;br /&gt;&lt;br /&gt;But you can use JavaScript to execute a client side email program send the email using the "mailto" code. Here is an example:&lt;br /&gt;&lt;br /&gt;function myfunction(form)&lt;br /&gt;{&lt;br /&gt;tdata=document.myform.tbox1.value;&lt;br /&gt;location="mailto:mailid@domain.com?subject=...";&lt;br /&gt;return true;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;What is the functionality of the function strstr and stristr?&lt;br /&gt;strstr() returns part of a given string from the first occurrence of a given substring to the end of the string. For example: strstr("user@example.com","@") will return "@example.com".&lt;br /&gt;stristr() is idential to strstr() except that it is case insensitive.&lt;br /&gt;&lt;br /&gt;What is the difference between ereg_replace() and eregi_replace()?&lt;br /&gt;eregi_replace() function is identical to ereg_replace() except that it ignores case distinction when matching alphabetic characters.&lt;br /&gt;&lt;br /&gt;How do I find out the number of parameters passed into function9. ?&lt;br /&gt;func_num_args() function returns the number of parameters passed in.&lt;br /&gt;&lt;br /&gt;What is the purpose of the following files having extensions: frm, myd, and myi? What these files contain?&lt;br /&gt;In MySQL, the default table type is MyISAM.&lt;br /&gt;Each MyISAM table is stored on disk in three files. The files have names that begin with the table name and have an extension to indicate the file type.&lt;br /&gt;&lt;br /&gt;The '.frm' file stores the table definition.&lt;br /&gt;The data file has a '.MYD' (MYData) extension.&lt;br /&gt;The index file has a '.MYI' (MYIndex) extension,&lt;br /&gt;&lt;br /&gt;If the variable $a is equal to 5 and variable $b is equal to character a, what’s the value of $$b?&lt;br /&gt;100, it’s a reference to existing variable.&lt;br /&gt;&lt;br /&gt;Write a query for the following question&lt;br /&gt;The table tbl_sites contains the following data:&lt;br /&gt;&lt;br /&gt;-----------------------------------------------------&lt;br /&gt;Userid sitename country&lt;br /&gt;------------------------------------------------------&lt;br /&gt;1 sureshbabu indian&lt;br /&gt;2 PHPprogrammer andhra&lt;br /&gt;3 PHP.net usa&lt;br /&gt;4 PHPtalk.com germany&lt;br /&gt;5 MySQL.com usa&lt;br /&gt;6 sureshbabu canada&lt;br /&gt;7 PHPbuddy.com pakistan&lt;br /&gt;8. PHPtalk.com austria&lt;br /&gt;9. PHPfreaks.com sourthafrica&lt;br /&gt;10. PHPsupport.net russia&lt;br /&gt;11. sureshbabu australia&lt;br /&gt;12. sureshbabu nepal&lt;br /&gt;13. PHPtalk.com italy&lt;br /&gt;&lt;br /&gt;Write a select query that will be displayed the duplicated site name and how many times it is duplicated? …&lt;br /&gt;SELECT sitename, COUNT(*) AS NumOccurrences&lt;br /&gt;FROM tbl_sites&lt;br /&gt;GROUP BY sitename HAVING COUNT(*) &gt; 1&lt;br /&gt;&lt;br /&gt;How To Protect Special Characters in Query String?&lt;br /&gt;If you want to include special characters like spaces in the query string, you need to protect them by applying the urlencode() translation function. The script below shows how to use urlencode():&lt;br /&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;print("&lt;html&gt;");&lt;br /&gt;print("&lt;p&gt;Please click the links below"&lt;br /&gt;." to submit comments about FYICenter.com:&lt;/p&gt;");&lt;br /&gt;$comment = 'I want to say: "It\'s a good site! :-&gt;"';&lt;br /&gt;$comment = urlencode($comment);&lt;br /&gt;print("&lt;p&gt;"&lt;br /&gt;."&lt;a href="\" name="Guest&amp;amp;comment="$comment\"&gt;"&lt;br /&gt;."It's an excellent site!&lt;/a&gt;&lt;/p&gt;");&lt;br /&gt;$comment = 'This visitor said: "It\'s an average site! :-("';&lt;br /&gt;$comment = urlencode($comment);&lt;br /&gt;print("&lt;p&gt;"&lt;br /&gt;.'&lt;a href="processing_forms.php?'.$comment.'"&gt;'&lt;br /&gt;."It's an average site.&lt;/a&gt;&lt;/p&gt;");&lt;br /&gt;print("&lt;/html&gt;");&lt;br /&gt;?&gt;&lt;br /&gt;&lt;br /&gt;Are objects passed by value or by reference?&lt;br /&gt;Everything is passed by value.&lt;br /&gt;&lt;br /&gt;What are the differences between DROP a table and TRUNCATE a table?&lt;br /&gt;DROP TABLE table_name - This will delete the table and its data.&lt;br /&gt;&lt;br /&gt;TRUNCATE TABLE table_name - This will delete the data of the table, but not the table definition.&lt;br /&gt;&lt;br /&gt;What are the differences between GET and POST methods in form submitting, give the case where we can use GET and we can use POST methods?&lt;br /&gt;Anwser 1:&lt;br /&gt;&lt;br /&gt;When we submit a form, which has the GET method it displays pair of name/value used in the form at the address bar of the browser preceded by url. Post method doesn't display these values.&lt;br /&gt;&lt;br /&gt;Anwser 2:&lt;br /&gt;&lt;br /&gt;When you want to send short or small data, not containing ASCII characters, then you can use GET” Method. But for long data sending, say more then 100 character you can use POST method.&lt;br /&gt;&lt;br /&gt;Once most important difference is when you are sending the form with GET method. You can see the output which you are sending in the address bar. Whereas if you send the form with POST” method then user can not see that information.&lt;br /&gt;&lt;br /&gt;Anwser 3:&lt;br /&gt;&lt;br /&gt;What are "GET" and "POST"?&lt;br /&gt;&lt;br /&gt;GET and POST are methods used to send data to the server: With the GET method, the browser appends the data onto the URL. With the Post method, the data is sent as "standard input."&lt;br /&gt;&lt;br /&gt;Major Difference&lt;br /&gt;&lt;br /&gt;In simple words, in POST method data is sent by standard input (nothing shown in URL when posting while in GET method data is sent through query string.&lt;br /&gt;&lt;br /&gt;Ex: Assume we are logging in with username and password.&lt;br /&gt;&lt;br /&gt;GET: we are submitting a form to login.php, when we do submit or similar action, values are sent through visible query string (notice ./login.php?username=...&amp;amp;password=... as URL when executing the script login.php) and is retrieved by login.php by $_GET['username'] and $_GET['password'].&lt;br /&gt;&lt;br /&gt;POST: we are submitting a form to login.php, when we do submit or similar action, values are sent through invisible standard input (notice ./login.php) and is retrieved by login.php by $_POST['username'] and $_POST['password'].&lt;br /&gt;&lt;br /&gt;POST is assumed more secure and we can send lot more data than that of GET method is limited (they say Internet Explorer can take care of maximum 2083 character as a query string).&lt;br /&gt;&lt;br /&gt;Anwser 4:&lt;br /&gt;&lt;br /&gt;In the get method the data made available to the action page ( where data is received ) by the URL so data can be seen in the address bar. Not advisable if you are sending login info like password etc. In the post method the data will be available as data blocks and not as query string in case of get method.&lt;br /&gt;&lt;br /&gt;Anwser 5:&lt;br /&gt;&lt;br /&gt;When we submit a form, which has the GET method it pass value in the form of query string (set of name/value pair) and display along with URL. With GET we can a small data submit from the form (a set of 255 character) whereas Post method doesn't display value with URL. It passes value in the form of Object and we can submit large data from the form.&lt;br /&gt;&lt;br /&gt;Anwser 6:&lt;br /&gt;&lt;br /&gt;On the server side, the main difference between GET and POST is where the submitted is stored. The $_GET array stores data submitted by the GET method. The $_POST array stores data submitted by the POST method.&lt;br /&gt;On the browser side, the difference is that data submitted by the GET method will be displayed in the browser’s address field. Data submitted by the POST method will not be displayed anywhere on the browser.&lt;br /&gt;GET method is mostly used for submitting a small amount and less sensitive data. POST method is mostly used for submitting a large amount or sensitive data.&lt;br /&gt;&lt;br /&gt;How do you call a constructor for a parent class?&lt;br /&gt;parent::constructor($value)&lt;br /&gt;&lt;br /&gt;WHAT ARE THE DIFFERENT TYPES OF ERRORS IN PHP?&lt;br /&gt;Here are three basic types of runtime errors in PHP:&lt;br /&gt;&lt;br /&gt;1. Notices: These are trivial, non-critical errors that PHP encounters while executing a script - for example, accessing a variable that has not yet been defined. By default, such errors are not displayed to the user at all - although you can change this default behavior.&lt;br /&gt;&lt;br /&gt;2. Warnings: These are more serious errors - for example, attempting to include() a file which does not exist. By default, these errors are displayed to the user, but they do not result in script termination.&lt;br /&gt;&lt;br /&gt;3. Fatal errors: These are critical errors - for example, instantiating an object of a non-existent class, or calling a non-existent function. These errors cause the immediate termination of the script, and PHP's default behavior is to display them to the user when they take place.&lt;br /&gt;&lt;br /&gt;Internally, these variations are represented by twelve different error types&lt;br /&gt;&lt;br /&gt;What’s the special meaning of __sleep and __wakeup?&lt;br /&gt;__sleep returns the array of all the variables than need to be saved, while __wakeup retrieves them.&lt;br /&gt;&lt;br /&gt;How can we submit a form without a submit button?&lt;br /&gt;If you don't want to use the Submit button to submit a form, you can use normal hyper links to submit a form. But you need to use some JavaScript code in the URL of the link. For example:&lt;br /&gt;&lt;br /&gt;&lt;a href="javascript: document.myform.submit();"&gt;Submit Me&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Why doesn’t the following code print the newline properly? &lt;?php $str = ‘Hello, there.\nHow are you?\nThanks for visiting fyicenter’; print $str; ?&gt;&lt;br /&gt;Because inside the single quotes the \n character is not interpreted as newline, just as a sequence of two characters - \ and n.&lt;br /&gt;&lt;br /&gt;Would you initialize your strings with single quotes or double quotes?&lt;br /&gt;Since the data inside the single-quoted string is not parsed for variable substitution, it’s always a better idea speed-wise to initialize a string with single quotes, unless you specifically need variable substitution.&lt;br /&gt;&lt;br /&gt;How can we extract string 'abc.com ' from a string http://info@abc.com using regular expression of php?&lt;br /&gt;We can use the preg_match() function with "/.*@(.*)$/" as&lt;br /&gt;the regular expression pattern. For example:&lt;br /&gt;preg_match("/.*@(.*)$/","http://info@abc.com",$data);&lt;br /&gt;echo $data[1];&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;What is the difference between the functions unlink and unset?&lt;br /&gt;unlink() is a function for file system handling. It will simply delete the file in context.&lt;br /&gt;&lt;br /&gt;unset() is a function for variable management. It will make a variable undefined.&lt;br /&gt;&lt;br /&gt;How come the code works, but doesn’t for two-dimensional array of mine?&lt;br /&gt;Any time you have an array with more than one dimension, complex parsing syntax is required. print "Contents: {$arr[1][2]}" would’ve worked.&lt;br /&gt;&lt;br /&gt;How can we register the variables into a session?&lt;br /&gt;session_register($session_var);&lt;br /&gt;&lt;br /&gt;$_SESSION['var'] = 'value';&lt;br /&gt;&lt;br /&gt;What is the difference between characters \023 and \x23?&lt;br /&gt;The first one is octal 23, the second is hex 23.&lt;br /&gt;&lt;br /&gt;With a heredoc syntax, do I get variable substitution inside the heredoc contents?&lt;br /&gt;Yes.&lt;br /&gt;&lt;br /&gt;How can we submit form without a submit button?&lt;br /&gt;We can use a simple JavaScript code linked to an event trigger of any form field. In the JavaScript code, we can call the document.form.submit() function to submit the form. For example: &lt;input type="button" value="Save" onclick="document.form.submit()"&gt;&lt;br /&gt;&lt;br /&gt;How can we create a database using PHP and mysql?&lt;br /&gt;We can create MySQL database with the use of mysql_create_db($databaseName) to create a database.&lt;br /&gt;&lt;br /&gt;How many ways we can retrieve the date in result set of mysql using php?&lt;br /&gt;As individual objects so single record or as a set or arrays.&lt;br /&gt;&lt;br /&gt;Can we use include ("abc.php") two times in a php page "makeit.php"?&lt;br /&gt;Yes.&lt;br /&gt;&lt;br /&gt;For printing out strings, there are echo, print and printf. Explain the differences.&lt;br /&gt;echo is the most primitive of them, and just outputs the contents following the construct to the screen. print is also a construct (so parentheses are optional when calling it), but it returns TRUE on successful output and FALSE if it was unable to print out the string. However, you can pass multiple parameters to echo, like:&lt;br /&gt;&lt;br /&gt;&lt;?php echo 'Welcome ', 'to', ' ', 'fyicenter!'; ?&gt;&lt;br /&gt;&lt;br /&gt;and it will output the string "Welcome to fyicenter!" print does not take multiple parameters. It is also generally argued that echo is faster, but usually the speed advantage is negligible, and might not be there for future versions of PHP. printf is a function, not a construct, and allows such advantages as formatted output, but it’s the slowest way to print out data out of echo, print and printf.&lt;br /&gt;&lt;br /&gt;I am writing an application in PHP that outputs a printable version of driving directions. It contains some long sentences, and I am a neat freak, and would like to make sure that no line exceeds 50 characters. How do I accomplish that with PHP?&lt;br /&gt;On large strings that need to be formatted according to some length specifications, use wordwrap() or chunk_split().&lt;br /&gt;&lt;br /&gt;What’s the output of the ucwords function in this example?&lt;br /&gt;$formatted = ucwords("FYICENTER IS COLLECTION OF INTERVIEW QUESTIONS");&lt;br /&gt;print $formatted;&lt;br /&gt;What will be printed is FYICENTER IS COLLECTION OF INTERVIEW QUESTIONS.&lt;br /&gt;ucwords() makes every first letter of every word capital, but it does not lower-case anything else. To avoid this, and get a properly formatted string, it’s worth using strtolower() first.&lt;br /&gt;&lt;br /&gt;What’s the difference between htmlentities() and htmlspecialchars()?&lt;br /&gt;htmlspecialchars only takes care of &lt;, &gt;, single quote ‘, double quote " and ampersand. htmlentities translates all occurrences of character sequences that have different meaning in HTML.&lt;br /&gt;&lt;br /&gt;How can we extract string "abc.com" from a string "mailto:info@abc.com?subject=Feedback" using regular expression of PHP?&lt;br /&gt;$text = "mailto:info@abc.com?subject=Feedback";&lt;br /&gt;preg_match('|.*@([^?]*)|', $text, $output);&lt;br /&gt;echo $output[1];&lt;br /&gt;&lt;br /&gt;Note that the second index of $output, $output[1], gives the match, not the first one, $output[0].&lt;br /&gt;&lt;br /&gt;So if md5() generates the most secure hash, why would you ever use the less secure crc32() and sha1()?&lt;br /&gt;Crypto usage in PHP is simple, but that doesn’t mean it’s free. First off, depending on the data that you’re encrypting, you might have reasons to store a 32-bit value in the database instead of the 160-bit value to save on space. Second, the more secure the crypto is, the longer is the computation time to deliver the hash value. A high volume site might be significantly slowed down, if frequent md5() generation is required.&lt;br /&gt;&lt;br /&gt;How can we destroy the session, how can we unset the variable of a session?&lt;br /&gt;session_unregister() - Unregister a global variable from the current session&lt;br /&gt;session_unset() - Free all session variables&lt;br /&gt;&lt;br /&gt;What are the different functions in sorting an array?&lt;br /&gt;Sorting functions in PHP:&lt;br /&gt;asort()&lt;br /&gt;arsort()&lt;br /&gt;ksort()&lt;br /&gt;krsort()&lt;br /&gt;uksort()&lt;br /&gt;sort()&lt;br /&gt;natsort()&lt;br /&gt;rsort()&lt;br /&gt;&lt;br /&gt;How can we know the count/number of elements of an array?&lt;br /&gt;2 ways:&lt;br /&gt;a) sizeof($array) - This function is an alias of count()&lt;br /&gt;b) count($urarray) - This function returns the number of elements in an array.&lt;br /&gt;Interestingly if you just pass a simple var instead of an array, count() will return 1.&lt;br /&gt;&lt;br /&gt;How many ways we can pass the variable through the navigation between the pages?&lt;br /&gt;At least 3 ways:&lt;br /&gt;&lt;br /&gt;1. Put the variable into session in the first page, and get it back from session in the next page.&lt;br /&gt;2. Put the variable into cookie in the first page, and get it back from the cookie in the next page.&lt;br /&gt;3. Put the variable into a hidden form field, and get it back from the form in the next page.&lt;br /&gt;&lt;br /&gt;What is the maximum length of a table name, a database name, or a field name in MySQL?&lt;br /&gt;Database name: 64 characters&lt;br /&gt;Table name: 64 characters&lt;br /&gt;Column name: 64 characters&lt;br /&gt;&lt;br /&gt;How many values can the SET function of MySQL take?&lt;br /&gt;MySQL SET function can take zero or more values, but at the maximum it can take 64 values.&lt;br /&gt;&lt;br /&gt;What are the other commands to know the structure of a table using MySQL commands except EXPLAIN command?&lt;br /&gt;DESCRIBE table_name;&lt;br /&gt;&lt;br /&gt;How can we find the number of rows in a table using MySQL?&lt;br /&gt;Use this for MySQL&lt;br /&gt;&lt;br /&gt;SELECT COUNT(*) FROM table_name;&lt;br /&gt;&lt;br /&gt;What’s the difference between md5(), crc32() and sha1() crypto on PHP?&lt;br /&gt;The major difference is the length of the hash generated. CRC32 is, evidently, 32 bits, while sha1() returns a 128 bit value, and md5() returns a 160 bit value. This is important when avoiding collisions.&lt;br /&gt;&lt;br /&gt;How can we find the number of rows in a result set using PHP?&lt;br /&gt;Here is how can you find the number of rows in a result set in PHP:&lt;br /&gt;&lt;br /&gt;$result = mysql_query($any_valid_sql, $database_link);&lt;br /&gt;$num_rows = mysql_num_rows($result);&lt;br /&gt;echo "$num_rows rows found";&lt;br /&gt;&lt;br /&gt;How many ways we can we find the current date using MySQL?&lt;br /&gt;SELECT CURDATE();&lt;br /&gt;SELECT CURRENT_DATE();&lt;br /&gt;SELECT CURTIME();&lt;br /&gt;SELECT CURRENT_TIME();&lt;br /&gt;&lt;br /&gt;Give the syntax of GRANT commands?&lt;br /&gt;The generic syntax for GRANT is as following&lt;br /&gt;&lt;br /&gt;GRANT [rights] on [database] TO [username@hostname] IDENTIFIED BY [password]&lt;br /&gt;&lt;br /&gt;Now rights can be:&lt;br /&gt;a) ALL privilages&lt;br /&gt;b) Combination of CREATE, DROP, SELECT, INSERT, UPDATE and DELETE etc.&lt;br /&gt;&lt;br /&gt;We can grant rights on all databse by usingh *.* or some specific database by database.* or a specific table by database.table_name.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Give the syntax of REVOKE commands?&lt;br /&gt;The generic syntax for revoke is as following&lt;br /&gt;&lt;br /&gt;REVOKE [rights] on [database] FROM [username@hostname]&lt;br /&gt;&lt;br /&gt;Now rights can be:&lt;br /&gt;a) ALL privilages&lt;br /&gt;b) Combination of CREATE, DROP, SELECT, INSERT, UPDATE and DELETE etc.&lt;br /&gt;&lt;br /&gt;We can grant rights on all databse by usingh *.* or some specific database by database.* or a specific table by database.table_name.&lt;br /&gt;&lt;br /&gt;Answer the questions with the following assumption&lt;br /&gt;The structure of table view buyers is as follows:&lt;br /&gt;+-------------+-------------+------+-----+---------+----------------+&lt;br /&gt;| Field       | Type        | Null | Key | Default | Extra          |&lt;br /&gt;+-------------+-------------+------+-----+---------+----------------+&lt;br /&gt;| user_pri_id | int(15)     |      | PRI | NULL    | auto_increment |&lt;br /&gt;| userid      | varchar(10) | YES  |     | NULL    |                |&lt;br /&gt;+-------------+-------------+------+-----+---------+----------------+&lt;br /&gt;The value of user_pri_id of the last row is 2345. What will happen in the following conditions?&lt;br /&gt;Condition 1: Delete all the rows and insert another row. What is the starting value for this auto incremented field user_pri_id?&lt;br /&gt;Condition 2: Delete the last row (having the field value 2345) and insert another row. What is the value for this auto incremented field user_pri_id?&lt;br /&gt;In both conditions, the value of this auto incremented field user_pri_id is 2346.&lt;br /&gt;&lt;br /&gt;What is the difference between CHAR and VARCHAR data types?&lt;br /&gt;CHAR is a fixed length data type. CHAR(n) will take n characters of storage even if you enter less than n characters to that column. For example, "Hello!" will be stored as "Hello! " in CHAR(10) column.&lt;br /&gt;VARCHAR is a variable length data type. VARCHAR(n) will take only the required storage for the actual number of characters entered to that column. For example, "Hello!" will be stored as "Hello!" in VARCHAR(10) column.&lt;br /&gt;How can we encrypt and decrypt a data present in a mysql table using mysql?&lt;br /&gt;AES_ENCRYPT() and AES_DECRYPT()&lt;br /&gt;&lt;br /&gt;Will comparison of string "10" and integer 11 work in PHP?&lt;br /&gt;Yes, internally PHP will cast everything to the integer type, so numbers 10 and 11 will be compared.&lt;br /&gt;&lt;br /&gt;What is the functionality of MD5 function in PHP?&lt;br /&gt;string md5(string)&lt;br /&gt;&lt;br /&gt;It calculates the MD5 hash of a string. The hash is a 32-character hexadecimal number.&lt;br /&gt;&lt;br /&gt;How can I load data from a text file into a table?&lt;br /&gt;The MySQL provides a LOAD DATA INFILE command. You can load data from a file. Great tool but you need to make sure that:&lt;br /&gt;&lt;br /&gt;a) Data must be delimited&lt;br /&gt;b) Data fields must match table columns correctly&lt;br /&gt;&lt;br /&gt;How can we know the number of days between two given dates using MySQL?&lt;br /&gt;Use DATEDIFF()&lt;br /&gt;&lt;br /&gt;SELECT DATEDIFF(NOW(),'2006-07-01');&lt;br /&gt;&lt;br /&gt;How can we change the name of a column of a table?&lt;br /&gt;This will change the name of column:&lt;br /&gt;&lt;br /&gt;ALTER TABLE table_name CHANGE old_colm_name new_colm_name&lt;br /&gt;&lt;br /&gt;How can we change the data type of a column of a table?&lt;br /&gt;This will change the data type of a column:&lt;br /&gt;&lt;br /&gt;ALTER TABLE table_name CHANGE colm_name same_colm_name [new data type]&lt;br /&gt;&lt;br /&gt;What is the difference between GROUP BY and ORDER BY in SQL?&lt;br /&gt;To sort a result, use an ORDER BY clause.&lt;br /&gt;The most general way to satisfy a GROUP BY clause is to scan the whole table and create a new temporary table where all rows from each group are consecutive, and then use this temporary table to discover groups and apply aggregate functions (if any).&lt;br /&gt;ORDER BY [col1],[col2],...[coln]; Tells DBMS according to what columns it should sort the result. If two rows will hawe the same value in col1 it will try to sort them according to col2 and so on.&lt;br /&gt;GROUP BY [col1],[col2],...[coln]; Tells DBMS to group (aggregate) results with same value of column col1. You can use COUNT(col1), SUM(col1), AVG(col1) with it, if you want to count all items in group, sum all values or view average.&lt;br /&gt;&lt;br /&gt;What is meant by MIME?&lt;br /&gt;Answer 1:&lt;br /&gt;MIME is Multipurpose Internet Mail Extensions is an Internet standard for the format of e-mail. However browsers also uses MIME standard to transmit files. MIME has a header which is added to a beginning of the data. When browser sees such header it shows the data as it would be a file (for example image)&lt;br /&gt;&lt;br /&gt;Some examples of MIME types:&lt;br /&gt;audio/x-ms-wmp&lt;br /&gt;image/png&lt;br /&gt;aplication/x-shockwave-flash&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Answer 2:&lt;br /&gt;Multipurpose Internet Mail Extensions.&lt;br /&gt;WWW's ability to recognize and handle files of different types is largely dependent on the use of the MIME (Multipurpose Internet Mail Extensions) standard. The standard provides for a system of registration of file types with information about the applications needed to process them. This information is incorporated into Web server and browser software, and enables the automatic recognition and display of registered file types. …&lt;br /&gt;&lt;br /&gt;How can we know that a session is started or not?&lt;br /&gt;A session starts by session_start() function.&lt;br /&gt;This session_start() is always declared in header portion. it always declares first. then we write session_register().&lt;br /&gt;&lt;br /&gt;What are the differences between mysql_fetch_array(), mysql_fetch_object(), mysql_fetch_row()?&lt;br /&gt;Answer 1:&lt;br /&gt;mysql_fetch_array() -&gt; Fetch a result row as a combination of associative array and regular array.&lt;br /&gt;mysql_fetch_object() -&gt; Fetch a result row as an object.&lt;br /&gt;mysql_fetch_row() -&gt; Fetch a result set as a regular array().&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Answer 2:&lt;br /&gt;The difference between mysql_fetch_row() and mysql_fetch_array() is that the first returns the results in a numeric array ($row[0], $row[1], etc.), while the latter returns a the results an array containing both numeric and associative keys ($row['name'], $row['email'], etc.). mysql_fetch_object() returns an object ($row-&gt;name, $row-&gt;email, etc.).&lt;br /&gt;&lt;br /&gt;If we login more than one browser windows at the same time with same user and after that we close one window, then is the session is exist to other windows or not? And if yes then why? If no then why?&lt;br /&gt;Session depends on browser. If browser is closed then session is lost. The session data will be deleted after session time out. If connection is lost and you recreate connection, then session will continue in the browser.&lt;br /&gt;&lt;br /&gt;What are the MySQL database files stored in system ?&lt;br /&gt;Data is stored in name.myd&lt;br /&gt;Table structure is stored in name.frm&lt;br /&gt;Index is stored in name.myi&lt;br /&gt;&lt;br /&gt;What is the difference between PHP4 and PHP5?&lt;br /&gt;PHP4 cannot support oops concepts and Zend engine 1 is used.&lt;br /&gt;&lt;br /&gt;PHP5 supports oops concepts and Zend engine 2 is used.&lt;br /&gt;Error supporting is increased in PHP5.&lt;br /&gt;XML and SQLLite will is increased in PHP5.&lt;br /&gt;&lt;br /&gt;Can we use include(abc.PHP) two times in a PHP page makeit.PHP”?&lt;br /&gt;Yes we can include that many times we want, but here are some things to make sure of:&lt;br /&gt;(including abc.PHP, the file names are case-sensitive)&lt;br /&gt;there shouldn't be any duplicate function names, means there should not be functions or classes or variables with the same name in abc.PHP and makeit.php&lt;br /&gt;&lt;br /&gt;What are the differences between mysql_fetch_array(), mysql_fetch_object(), mysql_fetch_row()?&lt;br /&gt;mysql_fetch_array - Fetch a result row as an associative array and a numeric array.&lt;br /&gt;&lt;br /&gt;mysql_fetch_object - Returns an object with properties that correspond to the fetched row and moves the internal data pointer ahead. Returns an object with properties that correspond to the fetched row, or FALSE if there are no more rows&lt;br /&gt;&lt;br /&gt;mysql_fetch_row() - Fetches one row of data from the result associated with the specified result identifier. The row is returned as an array. Each result column is stored in an array offset, starting at offset 0.&lt;br /&gt;&lt;br /&gt;What is meant by nl2br()?&lt;br /&gt;Anwser1:&lt;br /&gt;nl2br() inserts a HTML tag &lt;br /&gt; before all new line characters \n in a string.&lt;br /&gt;&lt;br /&gt;echo nl2br("god bless \n you");&lt;br /&gt;&lt;br /&gt;output:&lt;br /&gt;god bless&lt;br /&gt;&lt;br /&gt;you&lt;br /&gt;&lt;br /&gt;How can we encrypt and decrypt a data presented in a table using MySQL?&lt;br /&gt;You can use functions: AES_ENCRYPT() and AES_DECRYPT() like:&lt;br /&gt;&lt;br /&gt;AES_ENCRYPT(str, key_str)&lt;br /&gt;AES_DECRYPT(crypt_str, key_str)&lt;br /&gt;&lt;br /&gt;How can I retrieve values from one database server and store them in other database server using PHP?&lt;br /&gt;For this purpose, you can first read the data from one server into session variables. Then connect to other server and simply insert the data into the database.&lt;br /&gt;&lt;br /&gt;WHO IS THE FATHER OF PHP AND WHAT IS THE CURRENT VERSION OF PHP AND MYSQL?&lt;br /&gt;Rasmus Lerdorf.&lt;br /&gt;PHP 5.1. Beta&lt;br /&gt;MySQL 5.0&lt;br /&gt;&lt;br /&gt;IN HOW MANY WAYS WE CAN RETRIEVE DATA IN THE RESULT SET OF MYSQL USING PHP?&lt;br /&gt;mysql_fetch_array - Fetch a result row as an associative array, a numeric array, or both&lt;br /&gt;mysql_fetch_assoc - Fetch a result row as an associative array&lt;br /&gt;mysql_fetch_object - Fetch a result row as an object&lt;br /&gt;mysql_fetch_row —- Get a result row as an enumerated array&lt;br /&gt;&lt;br /&gt;What are the functions for IMAP?&lt;br /&gt;imap_body - Read the message body&lt;br /&gt;imap_check - Check current mailbox&lt;br /&gt;imap_delete - Mark a message for deletion from current mailbox&lt;br /&gt;imap_mail - Send an email message&lt;br /&gt;&lt;br /&gt;What are encryption functions in PHP?&lt;br /&gt;CRYPT()&lt;br /&gt;MD5()&lt;br /&gt;&lt;br /&gt;What is the difference between htmlentities() and htmlspecialchars()?&lt;br /&gt;htmlspecialchars() - Convert some special characters to HTML entities (Only the most widely used)&lt;br /&gt;htmlentities() - Convert ALL special characters to HTML entities&lt;br /&gt;&lt;br /&gt;What is the functionality of the function htmlentities?&lt;br /&gt;htmlentities() - Convert all applicable characters to HTML entities&lt;br /&gt;This function is identical to htmlspecialchars() in all ways, except with htmlentities(), all characters which have HTML character entity equivalents are translated into these entities.&lt;br /&gt;&lt;br /&gt;How can we get the properties (size, type, width, height) of an image using php image functions?&lt;br /&gt;To know the image size use getimagesize() function&lt;br /&gt;To know the image width use imagesx() function&lt;br /&gt;To know the image height use imagesy() function&lt;br /&gt;&lt;br /&gt;How can we increase the execution time of a php script?&lt;br /&gt;By the use of void set_time_limit(int seconds)&lt;br /&gt;Set the number of seconds a script is allowed to run. If this is reached, the script returns a fatal error. The default limit is 30 seconds or, if it exists, the max_execution_time value defined in the php.ini. If seconds is set to zero, no time limit is imposed.&lt;br /&gt;&lt;br /&gt;When called, set_time_limit() restarts the timeout counter from zero. In other words, if the timeout is the default 30 seconds, and 25 seconds into script execution a call such as set_time_limit(20) is made, the script will run for a total of 45 seconds before timing out.&lt;br /&gt;&lt;br /&gt;HOW CAN WE TAKE A BACKUP OF A MYSQL TABLE AND HOW CAN WE RESTORE IT?&lt;br /&gt;Answer 1:&lt;br /&gt;Create a full backup of your database: shell&gt; mysqldump tab=/path/to/some/dir opt db_name&lt;br /&gt;Or: shell&gt; mysqlhotcopy db_name /path/to/some/dir&lt;br /&gt;&lt;br /&gt;The full backup file is just a set of SQL statements, so restoring it is very easy:&lt;br /&gt;&lt;br /&gt;shell&gt; mysql "."Executed";&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Answer 2:&lt;br /&gt;To backup: BACKUP TABLE tbl_name TO /path/to/backup/directory&lt;br /&gt;’ To restore: RESTORE TABLE tbl_name FROM /path/to/backup/directory&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;mysqldump: Dumping Table Structure and Data&lt;br /&gt;&lt;br /&gt;Utility to dump a database or a collection of database for backup or for transferring the data to another SQL server (not necessarily a MySQL server). The dump will contain SQL statements to create the table and/or populate the table.&lt;br /&gt;-t, no-create-info&lt;br /&gt;Don't write table creation information (the CREATE TABLE statement).&lt;br /&gt;-d, no-data&lt;br /&gt;Don't write any row information for the table. This is very useful if you just want to get a dump of the structure for a table!&lt;br /&gt;&lt;br /&gt;How to set cookies?&lt;br /&gt;setcookie('variable','value','time')&lt;br /&gt;;&lt;br /&gt;variable - name of the cookie variable&lt;br /&gt;value - value of the cookie variable&lt;br /&gt;time - expiry time&lt;br /&gt;Example: setcookie('Test',$i,time()+3600);&lt;br /&gt;&lt;br /&gt;Test - cookie variable name&lt;br /&gt;$i - value of the variable 'Test'&lt;br /&gt;time()+3600 - denotes that the cookie will expire after an one hour&lt;br /&gt;&lt;br /&gt;How to reset/destroy a cookie&lt;br /&gt;Reset a cookie by specifying expire time in the past:&lt;br /&gt;Example: setcookie('Test',$i,time()-3600); // already expired time&lt;br /&gt;&lt;br /&gt;Reset a cookie by specifying its name only&lt;br /&gt;Example: setcookie('Test');&lt;br /&gt;&lt;br /&gt;WHAT TYPES OF IMAGES THAT PHP SUPPORTS?&lt;br /&gt;Using imagetypes() function to find out what types of images are supported in your PHP engine.&lt;br /&gt;imagetypes() - Returns the image types supported.&lt;br /&gt;This function returns a bit-field corresponding to the image formats supported by the version of GD linked into PHP. The following bits are returned, IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP | IMG_XPM.&lt;br /&gt;&lt;br /&gt;CHECK IF A VARIABLE IS AN INTEGER IN JAVASCRIPT&lt;br /&gt;var myValue =9.8;&lt;br /&gt;if(parseInt(myValue)== myValue)&lt;br /&gt;alert('Integer');&lt;br /&gt;else&lt;br /&gt;alert('Not an integer');&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Tools used for drawing ER diagrams.&lt;br /&gt;Case Studio&lt;br /&gt;Smart Draw&lt;br /&gt;&lt;br /&gt;How can I know that a variable is a number or not using a JavaScript?&lt;br /&gt;Answer 1:&lt;br /&gt;bool is_numeric( mixed var)&lt;br /&gt;Returns TRUE if var is a number or a numeric string, FALSE otherwise.&lt;br /&gt;&lt;br /&gt;Answer 2:&lt;br /&gt;Definition and Usage&lt;br /&gt;The isNaN() function is used to check if a value is not a number.&lt;br /&gt;&lt;br /&gt;Syntax&lt;br /&gt;isNaN(number)&lt;br /&gt;&lt;br /&gt;Parameter Description&lt;br /&gt;number Required. The value to be tested&lt;br /&gt;&lt;br /&gt;How can we submit from without a submit button?&lt;br /&gt;Trigger the JavaScript code on any event ( like onSelect of drop down list box, onfocus, etc ) document.myform.submit(); This will submit the form.&lt;br /&gt;&lt;br /&gt;How many ways can we get the value of current session id?&lt;br /&gt;session_id() returns the session id for the current session.&lt;br /&gt;&lt;br /&gt;How can we destroy the cookie?&lt;br /&gt;Set the cookie with a past expiration time.&lt;br /&gt;&lt;br /&gt;What are the current versions of Apache, PHP, and MySQL?&lt;br /&gt;PHP: PHP 5.1.2&lt;br /&gt;MySQL: MySQL 5.1&lt;br /&gt;Apache: Apache 2.1&lt;br /&gt;&lt;br /&gt;What are the reasons for selecting LAMP (Linux, Apache, MySQL, Php) instead of combination of other software programs, servers and operating systems?&lt;br /&gt;All of those are open source resource. Security of linux is very very more than windows. Apache is a better server that IIS both in functionality and security. Mysql is world most popular open source database. Php is more faster that asp or any other scripting language.&lt;br /&gt;&lt;br /&gt;What are the features and advantages of OBJECT ORIENTED PROGRAMMING?&lt;br /&gt;One of the main advantages of OO programming is its ease of modification; objects can easily be modified and added to a system there by reducing maintenance costs. OO programming is also considered to be better at modeling the real world than is procedural programming. It allows for more complicated and flexible interactions. OO systems are also easier for non-technical personnel to understand and easier for them to participate in the maintenance and enhancement of a system because it appeals to natural human cognition patterns. For some systems, an OO approach can speed development time since many objects are standard across systems and can be reused. Components that manage dates, shipping, shopping carts, etc. can be purchased and easily modified for a specific system.&lt;br /&gt;&lt;br /&gt;What is the use of friend function?&lt;br /&gt;Friend functions&lt;br /&gt;Sometimes a function is best shared among a number of different classes. Such functions can be declared either as member functions of one class or as global functions. In either case they can be set to be friends of other classes, by using a friend specifier in the class that is admitting them. Such functions can use all attributes of the class which names them as a friend, as if they were themselves members of that class.&lt;br /&gt;A friend declaration is essentially a prototype for a member function, but instead of requiring an implementation with the name of that class attached by the double colon syntax, a global function or member function of another class provides the match.&lt;br /&gt;class mylinkage&lt;br /&gt;{&lt;br /&gt;private:&lt;br /&gt;mylinkage * prev;&lt;br /&gt;mylinkage * next;&lt;br /&gt;&lt;br /&gt;protected:&lt;br /&gt;friend void set_prev(mylinkage* L, mylinkage* N);&lt;br /&gt;void set_next(mylinkage* L);&lt;br /&gt;&lt;br /&gt;public:&lt;br /&gt;mylinkage * succ();&lt;br /&gt;mylinkage * pred();&lt;br /&gt;mylinkage();&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;void mylinkage::set_next(mylinkage* L) { next = L; }&lt;br /&gt;&lt;br /&gt;void set_prev(mylinkage * L, mylinkage * N ) { N-&gt;prev = L; }&lt;br /&gt;&lt;br /&gt;Friends in other classes&lt;br /&gt;It is possible to specify a member function of another class as a friend as follows:&lt;br /&gt;class C&lt;br /&gt;{&lt;br /&gt;friend int B::f1();&lt;br /&gt;};&lt;br /&gt;class B&lt;br /&gt;{&lt;br /&gt;int f1();&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;It is also possible to specify all the functions in another class as friends, by specifying the entire class as a friend.&lt;br /&gt;class A&lt;br /&gt;{&lt;br /&gt;friend class B;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;Friend functions allow binary operators to be defined which combine private data in a pair of objects. This is particularly powerful when using the operator overloading features of C++. We will return to it when we look at overloading.&lt;br /&gt;&lt;br /&gt;How can we get second of the current time using date function?&lt;br /&gt;$second = date("s");&lt;br /&gt;&lt;br /&gt;What is the maximum size of a file that can be uploaded using PHP and how can we change this?&lt;br /&gt;You can change maximum size of a file set upload_max_filesize variable in php.ini file&lt;br /&gt;&lt;br /&gt;How can I make a script that can be bilingual (supports English, German)?&lt;br /&gt;You can change charset variable in above line in the script to support bilanguage.&lt;br /&gt;&lt;br /&gt;What are the difference between abstract class and interface?&lt;br /&gt;Abstract class: abstract classes are the class where one or more methods are abstract but not necessarily all method has to be abstract. Abstract methods are the methods, which are declare in its class but not define. The definition of those methods must be in its extending class.&lt;br /&gt;&lt;br /&gt;Interface: Interfaces are one type of class where all the methods are abstract. That means all the methods only declared but not defined. All the methods must be define by its implemented class.&lt;br /&gt;&lt;br /&gt;What are the advantages of stored procedures, triggers, indexes?&lt;br /&gt;A stored procedure is a set of SQL commands that can be compiled and stored in the server. Once this has been done, clients don't need to keep re-issuing the entire query but can refer to the stored procedure. This provides better overall performance because the query has to be parsed only once, and less information needs to be sent between the server and the client. You can also raise the conceptual level by having libraries of functions in the server. However, stored procedures of course do increase the load on the database server system, as more of the work is done on the server side and less on the client (application) side. Triggers will also be implemented. A trigger is effectively a type of stored procedure, one that is invoked when a particular event occurs. For example, you can install a stored procedure that is triggered each time a record is deleted from a transaction table and that stored procedure automatically deletes the corresponding customer from a customer table when all his transactions are deleted. Indexes are used to find rows with specific column values quickly. Without an index, MySQL must begin with the first row and then read through the entire table to find the relevant rows. The larger the table, the more this costs. If the table has an index for the columns in question, MySQL can quickly determine the position to seek to in the middle of the data file without having to look at all the data. If a table has 1,000 rows, this is at least 100 times faster than reading sequentially. If you need to access most of the rows, it is faster to read sequentially, because this minimizes disk seeks.&lt;br /&gt;&lt;br /&gt;What is maximum size of a database in mysql?&lt;br /&gt;If the operating system or filesystem places a limit on the number of files in a directory, MySQL is bound by that constraint. The efficiency of the operating system in handling large numbers of files in a directory can place a practical limit on the number of tables in a database. If the time required to open a file in the directory increases significantly as the number of files increases, database performance can be adversely affected.&lt;br /&gt;The amount of available disk space limits the number of tables.&lt;br /&gt;MySQL 3.22 had a 4GB (4 gigabyte) limit on table size. With the MyISAM storage engine in MySQL 3.23, the maximum table size was increased to 65536 terabytes (2567 – 1 bytes). With this larger allowed table size, the maximum effective table size for MySQL databases is usually determined by operating system constraints on file sizes, not by MySQL internal limits.&lt;br /&gt;The InnoDB storage engine maintains InnoDB tables within a tablespace that can be created from several files. This allows a table to exceed the maximum individual file size. The tablespace can include raw disk partitions, which allows extremely large tables. The maximum tablespace size is 64TB.&lt;br /&gt;The following table lists some examples of operating system file-size limits. This is only a rough guide and is not intended to be definitive. For the most up-to-date information, be sure to check the documentation specific to your operating system.&lt;br /&gt;Operating System File-size Limit&lt;br /&gt;Linux 2.2-Intel 32-bit 2GB (LFS: 4GB)&lt;br /&gt;Linux 2.4+ (using ext3 filesystem) 4TB&lt;br /&gt;Solaris 9/10 16TB&lt;br /&gt;NetWare w/NSS filesystem 8TB&lt;br /&gt;Win32 w/ FAT/FAT32 2GB/4GB&lt;br /&gt;Win32 w/ NTFS 2TB (possibly larger)&lt;br /&gt;MacOS X w/ HFS+ 2TB&lt;br /&gt;&lt;br /&gt;Explain normalization concept?&lt;br /&gt;The normalization process involves getting our data to conform to three progressive normal forms, and a higher level of normalization cannot be achieved until the previous levels have been achieved (there are actually five normal forms, but the last two are mainly academic and will not be discussed).&lt;br /&gt;&lt;br /&gt;First Normal Form&lt;br /&gt;The First Normal Form (or 1NF) involves removal of redundant data from horizontal rows. We want to ensure that there is no duplication of data in a given row, and that every column stores the least amount of information possible (making the field atomic).&lt;br /&gt;&lt;br /&gt;Second Normal Form&lt;br /&gt;Where the First Normal Form deals with redundancy of data across a horizontal row, Second Normal Form (or 2NF) deals with redundancy of data in vertical columns. As stated earlier, the normal forms are progressive, so to achieve Second Normal Form, your tables must already be in First Normal Form.&lt;br /&gt;&lt;br /&gt;Third Normal Form&lt;br /&gt;I have a confession to make; I do not often use Third Normal Form. In Third Normal Form we are looking for data in our tables that is not fully dependant on the primary key, but dependant on another value in the table&lt;br /&gt;&lt;br /&gt;What’s the difference between accessing a class method via -&gt; and via ::?&lt;br /&gt;:: is allowed to access methods that can perform static operations, i.e. those, which do not require object initialization.&lt;br /&gt;&lt;br /&gt;What are the advantages and disadvantages of CASCADE STYLE SHEETS?&lt;br /&gt;External Style Sheets&lt;br /&gt;Advantages&lt;br /&gt;Can control styles for multiple documents at once Classes can be created for use on multiple HTML element types in many documents Selector and grouping methods can be used to apply styles under complex contexts&lt;br /&gt;&lt;br /&gt;Disadvantages&lt;br /&gt;An extra download is required to import style information for each document The rendering of the document may be delayed until the external style sheet is loaded Becomes slightly unwieldy for small quantities of style definitions&lt;br /&gt;&lt;br /&gt;Embedded Style Sheets&lt;br /&gt;Advantages&lt;br /&gt;Classes can be created for use on multiple tag types in the document Selector and grouping methods can be used to apply styles under complex contexts No additional downloads necessary to receive style information&lt;br /&gt;&lt;br /&gt;Disadvantage&lt;br /&gt;This method can not control styles for multiple documents at once&lt;br /&gt;&lt;br /&gt;Inline Styles&lt;br /&gt;Advantages&lt;br /&gt;Useful for small quantities of style definitions Can override other style specification methods at the local level so only exceptions need to be listed in conjunction with other style methods&lt;br /&gt;&lt;br /&gt;Disadvantages&lt;br /&gt;Does not distance style information from content (a main goal of SGML/HTML) Can not control styles for multiple documents at once Author can not create or control classes of elements to control multiple element types within the document Selector grouping methods can not be used to create complex element addressing scenarios&lt;br /&gt;&lt;br /&gt;What type of inheritance that php supports?&lt;br /&gt;In PHP an extended class is always dependent on a single base class, that is, multiple inheritance is not supported. Classes are extended using the keyword 'extends'.&lt;br /&gt;&lt;br /&gt;How can increase the performance of MySQL select query?&lt;br /&gt;We can use LIMIT to stop MySql for further search in table after we have received our required no. of records, also we can use LEFT JOIN or RIGHT JOIN instead of full join in cases we have related data in two or more tables.&lt;br /&gt;&lt;br /&gt;How can we change the name of a column of a table?&lt;br /&gt;MySQL query to rename table: RENAME TABLE tbl_name TO new_tbl_name&lt;br /&gt;or,&lt;br /&gt;ALTER TABLE tableName CHANGE OldName newName.&lt;br /&gt;&lt;br /&gt;When you want to show some part of a text displayed on an HTML page in red font color? What different possibilities are there to do this? What are the advantages/disadvantages of these methods?&lt;br /&gt;There are 2 ways to show some part of a text in red:&lt;br /&gt;&lt;br /&gt;1. Using HTML tag &lt;span style="color:red;"&gt;&lt;br /&gt;2. Using HTML tag &lt;span style="color: red"&gt;&lt;br /&gt;&lt;br /&gt;When viewing an HTML page in a Browser, the Browser often keeps this page in its cache. What can be possible advantages/disadvantages of page caching? How can you prevent caching of a certain page (please give several alternate solutions)?&lt;br /&gt;When you use the metatag in the header section at the beginning of an HTML Web page, the Web page may still be cached in the Temporary Internet Files folder.&lt;br /&gt;&lt;br /&gt;A page that Internet Explorer is browsing is not cached until half of the 64 KB buffer is filled. Usually, metatags are inserted in the header section of an HTML document, which appears at the beginning of the document. When the HTML code is parsed, it is read from top to bottom. When the metatag is read, Internet Explorer looks for the existence of the page in cache at that exact moment. If it is there, it is removed. To properly prevent the Web page from appearing in the cache, place another header section at the end of the HTML document. For example:&lt;br /&gt;&lt;br /&gt;What are the different ways to login to a remote server? Explain the means, advantages and disadvantages?&lt;br /&gt;There is at least 3 ways to logon to a remote server:&lt;br /&gt;Use ssh or telnet if you concern with security&lt;br /&gt;You can also use rlogin to logon to a remote server.&lt;br /&gt;&lt;br /&gt;Please give a regular expression (preferably Perl/PREG style), which can be used to identify the URL from within a HTML link tag.&lt;br /&gt;Try this: /href="([^"]*)"/i&lt;br /&gt;&lt;br /&gt;How can I use the COM components in php?&lt;br /&gt;The COM class provides a framework to integrate (D)COM components into your PHP scripts.&lt;br /&gt;string COM::COM( string module_name [, string server_name [, int codepage]]) - COM class constructor.&lt;br /&gt;&lt;br /&gt;Parameters:&lt;br /&gt;&lt;br /&gt;module_name: name or class-id of the requested component.&lt;br /&gt;server_name: name of the DCOM server from which the component should be fetched. If NULL, localhost is assumed. To allow DCOM com, allow_dcom has to be set to TRUE in php.ini.&lt;br /&gt;codepage - specifies the codepage that is used to convert php-strings to unicode-strings and vice versa. Possible values are CP_ACP, CP_MACCP, CP_OEMCP, CP_SYMBOL, CP_THREAD_ACP, CP_UTF7 and CP_UTF8.&lt;br /&gt;Usage:&lt;br /&gt;$word-&gt;Visible = 1; //open an empty document&lt;br /&gt;$word-&gt;Documents-&gt;Add(); //do some weird stuff&lt;br /&gt;$word-&gt;Selection-&gt;TypeText("This is a test…");&lt;br /&gt;$word-&gt;Documents[1]-&gt;SaveAs("Useless test.doc"); //closing word&lt;br /&gt;$word-&gt;Quit(); //free the object&lt;br /&gt;$word-&gt;Release();&lt;br /&gt;$word = null;&lt;br /&gt;&lt;br /&gt;How many ways we can give the output to a browser?&lt;br /&gt;HTML output&lt;br /&gt;PHP, ASP, JSP, Servlet Function&lt;br /&gt;Script Language output Function&lt;br /&gt;Different Type of embedded Package to output to a browser&lt;br /&gt;&lt;br /&gt;What is the default session time in php and how can I change it?&lt;br /&gt;The default session time in php is until closing of browser&lt;br /&gt;&lt;br /&gt;What changes I have to do in php.ini file for file uploading?&lt;br /&gt;Make the following line uncomment like:&lt;br /&gt;; Whether to allow HTTP file uploads.&lt;br /&gt;file_uploads = On&lt;br /&gt;; Temporary directory for HTTP uploaded files (will use system default if not&lt;br /&gt;; specified).&lt;br /&gt;upload_tmp_dir = C:\apache2triad\temp&lt;br /&gt;; Maximum allowed size for uploaded files.&lt;br /&gt;upload_max_filesize = 2M&lt;br /&gt;&lt;br /&gt;How can I set a cron and how can I execute it in Unix, Linux, and windows?&lt;br /&gt;Cron is very simply a Linux module that allows you to run commands at predetermined times or intervals. In Windows, it's called Scheduled Tasks. The name Cron is in fact derived from the same word from which we get the word chronology, which means order of time.&lt;br /&gt;The easiest way to use crontab is via the crontab command.&lt;br /&gt;&lt;br /&gt;# crontab&lt;br /&gt;&lt;br /&gt;This command 'edits' the crontab. Upon employing this command, you will be able to enter the commands that you wish to run. My version of&lt;br /&gt;Linux uses the text editor vi. You can find information on using vi here.&lt;br /&gt;&lt;br /&gt;The syntax of this file is very important – if you get it wrong, your crontab will not function properly. The syntax of the file should be as follows:&lt;br /&gt;minutes hours day_of_month month day_of_week command&lt;br /&gt;&lt;br /&gt;All the variables, with the exception of the command itself, are numerical constants. In addition to an asterisk (*), which is a wildcard that allows any value, the ranges permitted for each field are as follows:&lt;br /&gt;&lt;br /&gt;Minutes: 0-59&lt;br /&gt;Hours: 0-23&lt;br /&gt;Day_of_month: 1-31&lt;br /&gt;Month: 1-12&lt;br /&gt;Weekday: 0-6&lt;br /&gt;&lt;br /&gt;We can also include multiple values for each entry, simply by separating each value with a comma.&lt;br /&gt;command can be any shell command and, as we will see momentarily, can also be used to execute a Web document such as a PHP file.&lt;br /&gt;So, if we want to run a script every Tuesday morning at 8:15 AM, our mycronjob file will contain the following content on a single line:&lt;br /&gt;&lt;br /&gt;15 8 * * 2 /path/to/scriptname&lt;br /&gt;&lt;br /&gt;This all seems simple enough, right? Not so fast! If you try to run a PHP script in this manner, nothing will happen (barring very special configurations that have PHP compiled as an executable, as opposed to an Apache module). The reason is that, in order for PHP to be parsed, it needs to be passed through Apache. In other words, the page needs to be called via a browser or other means of retrieving&lt;br /&gt;&lt;br /&gt;Web content. For our purposes, I'll assume that your server configuration includes wget, as is the case with most default configurations. To test your configuration, log in to shell. If you're using an RPM-based system (e.g. Redhat or Mandrake), type the following:&lt;br /&gt;&lt;br /&gt;# wget help&lt;br /&gt;&lt;br /&gt;If you are greeted with a wget package identification, it is installed in your system.&lt;br /&gt;You could execute the PHP by invoking wget on the URL to the page, like so:&lt;br /&gt;&lt;br /&gt;# wget http://www.example.com/file.php&lt;br /&gt;&lt;br /&gt;Now, let's go back to the mailstock.php file we created in the first part of this article. We saved it in our document root, so it should be accessible via the Internet. Remember that we wanted it to run at 4PM Eastern time, and send you your precious closing bell report? Since I'm located in the Eastern timezone, we can go ahead and set up our crontab to use 4:00, but if you live elsewhere, you might have to compensate for the time difference when setting this value.&lt;br /&gt;This is what my crontab will look like:&lt;br /&gt;&lt;br /&gt;0 4 * * 1,2,3,4,5 wget http://www.example.com/mailstock.php&lt;br /&gt;Steps for the payment gateway processing?&lt;br /&gt;An online payment gateway is the interface between your merchant account and your Web site. The online payment gateway allows you to immediately verify credit card transactions and authorize funds on a customer's credit card directly from your Web site. It then passes the transaction off to your merchant bank for processing, commonly referred to as transaction batching&lt;br /&gt;&lt;br /&gt;How many ways I can redirect a PHP page?&lt;br /&gt;Here are the possible ways of php page redirection.&lt;br /&gt;&lt;br /&gt;1. Using Java script:&lt;br /&gt;'; echo 'window.location.href="'.$filename.'";'; echo ''; echo ''; echo ''; echo ''; } } redirect('http://maosjb.com'); ?&gt;&lt;br /&gt;&lt;br /&gt;2. Using php function: header("Location:http://maosjb.com ");&lt;br /&gt;&lt;br /&gt;List out different arguments in PHP header function?&lt;br /&gt;void header ( string string [, bool replace [, int http_response_code]])&lt;br /&gt;&lt;br /&gt;What type of headers have to be added in the mail function to attach a file?&lt;br /&gt;$boundary = '--' . md5( uniqid ( rand() ) );&lt;br /&gt;$headers = "From: \"Me\"\n";&lt;br /&gt;$headers .= "MIME-Version: 1.0\n";&lt;br /&gt;$headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"";&lt;br /&gt;&lt;br /&gt;How to store the uploaded file to the final location?&lt;br /&gt;move_uploaded_file ( string filename, string destination)&lt;br /&gt;&lt;br /&gt;This function checks to ensure that the file designated by filename is a valid upload file (meaning that it was uploaded via PHP's HTTP POST upload mechanism). If the file is valid, it will be moved to the filename given by destination.&lt;br /&gt;&lt;br /&gt;If filename is not a valid upload file, then no action will occur, and move_uploaded_file() will return FALSE.&lt;br /&gt;&lt;br /&gt;If filename is a valid upload file, but cannot be moved for some reason, no action will occur, and move_uploaded_file() will return FALSE. Additionally, a warning will be issued.&lt;br /&gt;&lt;br /&gt;What is the difference between Reply-to and Return-path in the headers of a mail function?&lt;br /&gt;Reply-to: Reply-to is where to delivery the reply of the mail.&lt;br /&gt;&lt;br /&gt;Return-path: Return path is when there is a mail delivery failure occurs then where to delivery the failure notification.&lt;br /&gt;&lt;br /&gt;Explain about Type Juggling in php?&lt;br /&gt;PHP does not require (or support) explicit type definition in variable declaration; a variable's type is determined by the context in which that variable is used. That is to say, if you assign a string value to variable $var, $var becomes a string. If you then assign an integer value to $var, it becomes an integer.&lt;br /&gt;&lt;br /&gt;An example of PHP's automatic type conversion is the addition operator '+'. If any of the operands is a float, then all operands are evaluated as floats, and the result will be a float. Otherwise, the operands will be interpreted as integers, and the result will also be an integer. Note that this does NOT change the types of the operands themselves; the only change is in how the operands are evaluated.&lt;br /&gt;&lt;br /&gt;$foo += 2; // $foo is now an integer (2)&lt;br /&gt;$foo = $foo + 1.3; // $foo is now a float (3.3)&lt;br /&gt;$foo = 5 + "10 Little Piggies"; // $foo is integer (15)&lt;br /&gt;$foo = 5 + "10 Small Pigs"; // $foo is integer (15)&lt;br /&gt;&lt;br /&gt;If the last two examples above seem odd, see String conversion to numbers.&lt;br /&gt;If you wish to change the type of a variable, see settype().&lt;br /&gt;If you would like to test any of the examples in this section, you can use the var_dump() function.&lt;br /&gt;Note: The behavior of an automatic conversion to array is currently undefined.&lt;br /&gt;&lt;br /&gt;Since PHP (for historical reasons) supports indexing into strings via offsets using the same syntax as array indexing, the example above leads to a problem: should $a become an array with its first element being "f", or should "f" become the first character of the string $a? The current versions of PHP interpret the second assignment as a string offset identification, so $a becomes "f", the result of this automatic conversion however should be considered undefined. PHP 4 introduced the new curly bracket syntax to access characters in string, use this syntax instead of the one presented above:&lt;br /&gt;&lt;br /&gt;How can I embed a java programme in php file and what changes have to be done in php.ini file?&lt;br /&gt;There are two possible ways to bridge PHP and Java: you can either integrate PHP into a Java Servlet environment, which is the more stable and efficient solution, or integrate Java support into PHP. The former is provided by a SAPI module that interfaces with the Servlet server, the latter by this Java extension.&lt;br /&gt;The Java extension provides a simple and effective means for creating and invoking methods on Java objects from PHP. The JVM is created using JNI, and everything runs in-process.&lt;br /&gt;&lt;br /&gt;Example Code:&lt;br /&gt;&lt;br /&gt;getProperty('java.version') . ''; echo 'Java vendor=' . $system-&gt;getProperty('java.vendor') . ''; echo 'OS=' . $system-&gt;getProperty('os.name') . ' ' . $system-&gt;getProperty('os.version') . ' on ' . $system-&gt;getProperty('os.arch') . ' '; // java.util.Date example $formatter = new Java('java.text.SimpleDateFormat', "EEEE, MMMM dd, yyyy 'at' h:mm:ss a zzzz"); echo $formatter-&gt;format(new Java('java.util.Date')); ?&gt;&lt;br /&gt;&lt;br /&gt;The behaviour of these functions is affected by settings in php.ini.&lt;br /&gt;Table 1. Java configuration options&lt;br /&gt;Name&lt;br /&gt;Default&lt;br /&gt;Changeable&lt;br /&gt;java.class.path&lt;br /&gt;NULL&lt;br /&gt;PHP_INI_ALL&lt;br /&gt;Name Default Changeable&lt;br /&gt;java.home&lt;br /&gt;NULL&lt;br /&gt;PHP_INI_ALL&lt;br /&gt;java.library.path&lt;br /&gt;NULL&lt;br /&gt;PHP_INI_ALL&lt;br /&gt;java.library&lt;br /&gt;JAVALIB&lt;br /&gt;PHP_INI_ALL&lt;br /&gt;&lt;br /&gt;How To Turn On the Session Support?&lt;br /&gt;The session support can be turned on automatically at the site level, or manually in each PHP page script:&lt;br /&gt; Turning on session support automatically at the site level: Set session.auto_start = 1 in php.ini.&lt;br /&gt; Turning on session support manually in each page script: Call session_start() funtion.&lt;br /&gt;&lt;br /&gt;Explain the ternary conditional operator in PHP?&lt;br /&gt;Expression preceding the ? is evaluated, if it’s true, then the expression preceding the : is executed, otherwise, the expression following : is executed.&lt;br /&gt;&lt;br /&gt;What’s the difference between include and require?&lt;br /&gt;It’s how they handle failures. If the file is not found by require(), it will cause a fatal error and halt the execution of the script. If the file is not found by include(), a warning will be issued, but execution will continue.&lt;br /&gt;&lt;br /&gt;How many ways can we get the value of current session id?&lt;br /&gt;session_id() returns the session id for the current session.&lt;br /&gt;How can we destroy the cookie?&lt;br /&gt;Set the cookie in past.&lt;br /&gt;&lt;br /&gt;How To Read the Entire File into a Single String?&lt;br /&gt;If you have a file, and you want to read the entire file into a single string, you can use the file_get_contents() function. It opens the specified file, reads all characters in the file, and returns them in a single string. Here is a PHP script example on how to file_get_contents():&lt;br /&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;$file = file_get_contents("/windows/system32/drivers/etc/services");&lt;br /&gt;print("Size of the file: ".strlen($file)."\n");&lt;br /&gt;?&gt;&lt;br /&gt;&lt;br /&gt;This script will print:&lt;br /&gt;&lt;br /&gt;Size of the file: 7116&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2938427049868690639-1597894701576922620?l=scriptingfaqs.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://scriptingfaqs.blogspot.com/feeds/1597894701576922620/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2938427049868690639&amp;postID=1597894701576922620' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2938427049868690639/posts/default/1597894701576922620'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2938427049868690639/posts/default/1597894701576922620'/><link rel='alternate' type='text/html' href='http://scriptingfaqs.blogspot.com/2008/07/php-interview-questions-and-answers.html' title='PHP Interview Questions And Answers'/><author><name>Siebel Expert</name><uri>http://www.blogger.com/profile/11533458660230230361</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2938427049868690639.post-4123172337581472321</id><published>2008-07-04T08:19:00.000-07:00</published><updated>2008-12-23T03:54:08.335-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Perl'/><category scheme='http://www.blogger.com/atom/ns#' term='Scripting Language'/><title type='text'>Perl Script notes</title><content type='html'>4.1. Installation&lt;br /&gt;• On Microsoft Windows install ActivePerl from http://www.activestate.com/&lt;br /&gt;• On UNIX/Linux you usually have it installed in /usr/bin/perl or install ActivePerl&lt;br /&gt;4.2. Editors, IDEs&lt;br /&gt;• Emacs http://www.gnu.org/software/emacs/&lt;br /&gt;• vi, vim, gvim http://www.vim.org/&lt;br /&gt;• Crimson Editor http://www.crimsoneditor.com/&lt;br /&gt;• Notepad++ http://notepad-plus.sourceforge.net/&lt;br /&gt;• Textpad http://www.textpad.com/&lt;br /&gt;• Multi-Edit http://www.multiedit.com/&lt;br /&gt;• Komodo of ActiveState http://www.activestate.com/&lt;br /&gt;• Eclipse http://www.eclipse.org/&lt;br /&gt;• SlickEdit http://www.slickedit.com/&lt;br /&gt;4.3. Environment&lt;br /&gt;On the command line one can type:&lt;br /&gt;perl -e "print 42"&lt;br /&gt;perl -v&lt;br /&gt;perl -V&lt;br /&gt;4&lt;br /&gt;Chapter 4. First steps&lt;br /&gt;Example 4-1. examples/intro/hello_world.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;print "Hello world\n";&lt;br /&gt;print 42, "\n";&lt;br /&gt;run it by typing perl hello_world.pl&lt;br /&gt;On unix you can also make it executable: chmod u+x hello_world.pl and then run like: ./hello_world.pl&lt;br /&gt;A couple of notes&lt;br /&gt;• Strings and numbers&lt;br /&gt;• Strings must be quoted, you can use special characters such as "\n"&lt;br /&gt;• The print statement (Output) - gets comma delimitered list of things&lt;br /&gt;• ; after every statement&lt;br /&gt;4.4. Safety net&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;You should always use them as they are a safety net helping reduce mistakes.&lt;br /&gt;It is usually very hard to add this safety net after you already have some code.&lt;br /&gt;If the warnings you get don’t make sense add&lt;br /&gt;use diagnostics;&lt;br /&gt;line and you will get more verbose warnings.&lt;br /&gt;Why are use warnings and use strict so important even in small (&lt; 100 lines) scripts ?&lt;br /&gt;• Helps avoiding trouble with recoursive functions&lt;br /&gt;• Helps avoiding typos in variable names&lt;br /&gt;• Disables unintentional symbolic references&lt;br /&gt;• Reduces debugging time&lt;br /&gt;• Enables/enforces better coding standard =&gt; cleaner code, maintainability&lt;br /&gt;&lt;br /&gt;Chapter 4. First steps&lt;br /&gt;4.5. Comments&lt;br /&gt;# Comments for other developers&lt;br /&gt;print 42; # the answer&lt;br /&gt;4.6. Perl documentation&lt;br /&gt;perldoc perl&lt;br /&gt;perldoc perlsyn&lt;br /&gt;perldoc perlfunc&lt;br /&gt;perldoc -f print&lt;br /&gt;perldoc -q sort&lt;br /&gt;perldoc perlrun&lt;br /&gt;perldoc strict&lt;br /&gt;perldoc warnings&lt;br /&gt;An index: http://www.szabgab.com/articles/perlindex.html&lt;br /&gt;Web based: http://perldoc.perl.org/&lt;br /&gt;4.7. POD - Plain Old Documentation&lt;br /&gt;Example 4-2. examples/intro/documentation.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;print "Hello, there is no more code here\n";&lt;br /&gt;=head1 Explaining how PODs work&lt;br /&gt;Documentation starts any time there is a =tag&lt;br /&gt;at the beginning of a line (tag can be any word)&lt;br /&gt;and ends where there is a =cut at the beginning&lt;br /&gt;of a line.&lt;br /&gt;Around the =tags you have to add empty rows.&lt;br /&gt;A =tag can be anything but there are some tags&lt;br /&gt;that actually have meaning:&lt;br /&gt;=head1 Main heading&lt;br /&gt;&lt;br /&gt;Chapter 4. First steps&lt;br /&gt;=head2 Subtitle&lt;br /&gt;=over 4 start of indentation&lt;br /&gt;=item * element&lt;br /&gt;=back end of indentation&lt;br /&gt;Documentation of PODs can be found in B&lt;perldoc perlpod&gt;&lt;br /&gt;See a few examples:&lt;br /&gt;=head1 Main heading&lt;br /&gt;text after main heading&lt;br /&gt;=head2 Less important title&lt;br /&gt;more text&lt;br /&gt;some text shown verbatim&lt;br /&gt;more verbatim text typed in indented to the right&lt;br /&gt;=over 4&lt;br /&gt;=item *&lt;br /&gt;Issue&lt;br /&gt;=item *&lt;br /&gt;Other issue&lt;br /&gt;=back&lt;br /&gt;documentation ends here&lt;br /&gt;=cut&lt;br /&gt;print "Just documentation\n";&lt;br /&gt;perl examples/intro/documentation.pl&lt;br /&gt;perldoc examples/intro/documentation.pl&lt;br /&gt;4.8. Exercise: Hello world&lt;br /&gt;Try your environment:&lt;br /&gt;&lt;br /&gt;Chapter 4. First steps&lt;br /&gt;• Make sure you have access to the right version of Perl (5.8.x)&lt;br /&gt;• Check you can read the documentation.&lt;br /&gt;• Check if you have a good editor with syntax highlighting&lt;br /&gt;• Write a simple script that prints Hello world&lt;br /&gt;• Add comments to your code&lt;br /&gt;• Add user documentation to your code&lt;br /&gt; 8&lt;br /&gt;Chapter 5. Scalars&lt;br /&gt;A single piece of data either a number or a string is called a ’scalar’ in Perl.&lt;br /&gt;5.1. Numbers - integers, real or floating-point&lt;br /&gt;integer (decimal)&lt;br /&gt;26&lt;br /&gt;1_234_567_890&lt;br /&gt;integer (hex/oct/binary)&lt;br /&gt;0x1a # hex also written as hex("1a");&lt;br /&gt;032 # oct also written as oct("32");&lt;br /&gt;0b11010 # binary also written as oct("0b11010");&lt;br /&gt;# all 3 equal to 26 decimal&lt;br /&gt;real or floating-point&lt;br /&gt;3.5e+3 # 3500&lt;br /&gt;5.2. Scalar variables (use my)&lt;br /&gt;• Scalar variables always start with a $ sign, name is alphanumeric (a-zA-Z0-9) and underscore (_)&lt;br /&gt;• A scalar variable can hold either a string or a number&lt;br /&gt;• Value assignment to varaible is done by the = sign&lt;br /&gt;• Use the my keyword to declare variables (optional but recommended)&lt;br /&gt;$this_is_a_long_scalar_variable&lt;br /&gt;$ThisIsAlsoGoodButWeUseItLessInPerl&lt;br /&gt;$h&lt;br /&gt;$H # $h and $H are two different variables&lt;br /&gt;Example 5-1. examples/scalars/scalar_variables.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my $greeting = "Hello world\n";&lt;br /&gt;my $the_answer = 42;&lt;br /&gt;print $greeting;&lt;br /&gt;9&lt;br /&gt;Chapter 5. Scalars&lt;br /&gt;print $the_answer, "\n";&lt;br /&gt;A scalar can hold either string or numerical value. They can be changed any&lt;br /&gt;time. If a value was not given it holds the special value ’undef’.&lt;br /&gt;my $x; # the value is a special value called ’undef’&lt;br /&gt;5.3. Greeting with a name, Variable interpolation&lt;br /&gt;Example 5-2. examples/scalars/variable_interpolation.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my $name = "Foo";&lt;br /&gt;print "Hello ", $name, " - how are you ?\n";&lt;br /&gt;print "Hello $name - how are you ?\n";&lt;br /&gt;5.4. User Input&lt;br /&gt;Example 5-3. examples/scalars/read_from_stdin.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;print "Enter your name, please: ";&lt;br /&gt;my $name = &lt;STDIN&gt;;&lt;br /&gt;print "Hello $name, how are you ?\n";&lt;br /&gt;• STDIN - Standard Input (usually it is the keyboard)&lt;br /&gt;• Reading one line (till ENTER) from STDIN&lt;br /&gt;$ perl examples/read_from_stdin.pl&lt;br /&gt;Enter your name, please: Foo&lt;br /&gt;Hello Foo&lt;br /&gt;, how are you ?&lt;br /&gt;There is this problem of the newline&lt;br /&gt; 10&lt;br /&gt;Chapter 5. Scalars&lt;br /&gt;5.5. chomp&lt;br /&gt;Example 5-4. examples/scalars/read_from_stdin_chomp.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;print "Enter your name, please: ";&lt;br /&gt;my $name = &lt;STDIN&gt;;&lt;br /&gt;chomp $name;&lt;br /&gt;print "Hello $name, how are you ?\n";&lt;br /&gt;chomp will remove the new line "\n" character from the end of the string if there was one.&lt;br /&gt;5.6. Numerical Operators&lt;br /&gt;Example 5-5. examples/scalars/numerical_operators.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my $x = 3;&lt;br /&gt;my $y = 11;&lt;br /&gt;my $z = $x + $y;&lt;br /&gt;print "$z\n"; # 14&lt;br /&gt;$z = $x * $y;&lt;br /&gt;print "$z\n"; # 33&lt;br /&gt;print $y / $x, "\n"; # 3.66666666666667&lt;br /&gt;$z = $y % $x; # (modulus)&lt;br /&gt;print "$z\n"; # 2&lt;br /&gt;$z += 14; # is the same as $z = $z + 14;&lt;br /&gt;print "$z\n"; # 16&lt;br /&gt;$z++; # is the same as $z = $z + 1;&lt;br /&gt;$z--; # is the same as $z = $z - 1;&lt;br /&gt;$z = 23 ** 2; # exponentiation&lt;br /&gt;print "$z\n"; # 529&lt;br /&gt; 11&lt;br /&gt;Chapter 5. Scalars&lt;br /&gt;Example 5-6. examples/scalars/autoincrement.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my $x = 7;&lt;br /&gt;# Postfix ++ increments AFTER the OLD value was used&lt;br /&gt;my $y = $x++;&lt;br /&gt;print "y = $y, x = $x\n"; # y = 7, x = 8,&lt;br /&gt;$x = 7;&lt;br /&gt;$y = ++$x;&lt;br /&gt;print "y = $y, x = $x\n"; # y = 8, x = 8&lt;br /&gt;See also perldoc perlop for all the operators.&lt;br /&gt;5.7. String Operators&lt;br /&gt;Example 5-7. examples/scalars/string_operators.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my $x = "Hello";&lt;br /&gt;my $y = "World";&lt;br /&gt;# . is the concatenation operator, ataching ons string after the other&lt;br /&gt;my $z = $x . " " . $y; # the same as "$x $y"&lt;br /&gt;print $z, "\n"; # Hello World&lt;br /&gt;my $w = "Take " . (2 + 3); # you cannot write "Take (2 + 3)" here&lt;br /&gt;print "$w\n"; # Take 5&lt;br /&gt;$z .= "! "; # the same as $z = $z . "! ";&lt;br /&gt;print "’$z’\n"; # ’Hello World! ’&lt;br /&gt;# x is the string repetition operator&lt;br /&gt;my $q = $z x 3;&lt;br /&gt;print "’$q’\n"; # ’Hello World! Hello World! Hello World! ’&lt;br /&gt;See also perldoc perlop for all the operators.&lt;br /&gt; 12&lt;br /&gt;Chapter 5. Scalars&lt;br /&gt;5.8. Dividing two numbers given by the user&lt;br /&gt;Ask the user for two numbers and divide the first by the second number.&lt;br /&gt;Example 5-8. examples/scalars/divide.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;print "First number: ";&lt;br /&gt;my $x = &lt;STDIN&gt;;&lt;br /&gt;chomp $x;&lt;br /&gt;print "Second number: ";&lt;br /&gt;my $y = &lt;STDIN&gt;;&lt;br /&gt;chomp $y;&lt;br /&gt;my $z = $x / $y;&lt;br /&gt;print "The result is $z\n";&lt;br /&gt;$ perl examples/divide.pl&lt;br /&gt;First number: 27&lt;br /&gt;Second number: 3&lt;br /&gt;9&lt;br /&gt;$ perl examples/divide.pl&lt;br /&gt;First number: 27&lt;br /&gt;Second number: 0&lt;br /&gt;Illegal division by zero at examples/divide.pl line 9, &lt;STDIN&gt; line 2.&lt;br /&gt;5.9. Fixing the problem: Conditional statements: if&lt;br /&gt;Sometimes based on some condition a piece of code has to be executed or not.&lt;br /&gt;Example 5-9. examples/scalars/if_conditional.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;print "First number: ";&lt;br /&gt;my $x = &lt;STDIN&gt;;&lt;br /&gt;chomp $x;&lt;br /&gt;print "Second number: ";&lt;br /&gt;my $y = &lt;STDIN&gt;;&lt;br /&gt;chomp $y;&lt;br /&gt; 13&lt;br /&gt;Chapter 5. Scalars&lt;br /&gt;if ($y == 0) {&lt;br /&gt;print "Cannot divide by zero\n";&lt;br /&gt;} else {&lt;br /&gt;my $z = $x / $y;&lt;br /&gt;print "The result is $z\n";&lt;br /&gt;}&lt;br /&gt;5.10. Syntax of if statement&lt;br /&gt;{} are always required&lt;br /&gt;if (COND) {&lt;br /&gt;STATEMENTs;&lt;br /&gt;}&lt;br /&gt;if (COND) {&lt;br /&gt;STATEMENTs;&lt;br /&gt;} else {&lt;br /&gt;STATEMENTs;&lt;br /&gt;}&lt;br /&gt;if (COND_1) {&lt;br /&gt;A_STATEMENTs;&lt;br /&gt;} else {&lt;br /&gt;if (COND_2) {&lt;br /&gt;B_STATEMENTs;&lt;br /&gt;} else {&lt;br /&gt;if (COND_3) {&lt;br /&gt;C_STATEMENTs;&lt;br /&gt;} else {&lt;br /&gt;D_STATEMENTs;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;if (COND_1) {&lt;br /&gt;A_STATEMENTs;&lt;br /&gt;} elsif (COND_2) {&lt;br /&gt;B_STATEMENTs;&lt;br /&gt;} elsif (COND_3) {&lt;br /&gt;C_STATEMENTs;&lt;br /&gt;} else {&lt;br /&gt;D_STATEMENTs;&lt;br /&gt;}&lt;br /&gt; 14&lt;br /&gt;Chapter 5. Scalars&lt;br /&gt;5.11. Comparison operators&lt;br /&gt;Table 5-1. Comparison operators&lt;br /&gt;Numeric String (ASCII) Meaning&lt;br /&gt;== eq equal&lt;br /&gt;!= ne not equal&lt;br /&gt;&lt; lt less than&lt;br /&gt;&gt; gt greater than&lt;br /&gt;&lt;= le less than or equal&lt;br /&gt;&gt;= ge greater then or equal&lt;br /&gt;5.12. String - Number conversion&lt;br /&gt;Example 5-10. examples/scalars/string_number.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;print 3 . "", "\n";&lt;br /&gt;print 3.1 . "", "\n";&lt;br /&gt;print "3" + 0, "\n";&lt;br /&gt;print "3.1" + 0, "\n";&lt;br /&gt;print "3x" + 0, "\n"; # warning: Argument "3x" isn’t numeric in addition (+)&lt;br /&gt;print "3\n" + 0, "\n";&lt;br /&gt;print "3x7" + 0, "\n"; # warning: Argument "3x7" isn’t numeric in addition (+)&lt;br /&gt;print "" + 0, "\n"; # warning: Argument "" isn’t numeric in addition (+)&lt;br /&gt;print "z" + 0, "\n"; # warning: Argument "z" isn’t numeric in addition (+)&lt;br /&gt;print "z7" + 0, "\n"; # warning: Argument "z7" isn’t numeric in addition (+)&lt;br /&gt;5.13. Compare values&lt;br /&gt;Example 5-11. examples/scalars/compare_values.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my $first = &lt;STDIN&gt;;&lt;br /&gt;chomp $first;&lt;br /&gt; 15&lt;br /&gt;Chapter 5. Scalars&lt;br /&gt;my $other = &lt;STDIN&gt;;&lt;br /&gt;chomp $other;&lt;br /&gt;if ($first == $other) {&lt;br /&gt;print "The two numbers are the same\n";&lt;br /&gt;} else {&lt;br /&gt;print "The two numbers are NOT the same\n";&lt;br /&gt;}&lt;br /&gt;if ($first eq $other) {&lt;br /&gt;print "The two strings are the same\n";&lt;br /&gt;} else {&lt;br /&gt;print "The two strings are NOT the same\n";&lt;br /&gt;}&lt;br /&gt;if ($first &gt; $other) {&lt;br /&gt;print "First is a BIGGER number\n";&lt;br /&gt;} else {&lt;br /&gt;print "First is a smaller number\n";&lt;br /&gt;}&lt;br /&gt;if ($first gt $other) {&lt;br /&gt;print "First is a BIGGER string\n";&lt;br /&gt;} else {&lt;br /&gt;print "First is a smaller string\n";&lt;br /&gt;}&lt;br /&gt;5.14. Compare values - examples&lt;br /&gt;Table 5-2. Compare values&lt;br /&gt;Expression Value&lt;br /&gt;"12.0" == 12 TRUE&lt;br /&gt;"12.0" eq 12 FALSE&lt;br /&gt;2 &lt; 3 TRUE&lt;br /&gt;2 lt 3 TRUE&lt;br /&gt;12 &gt; 3 TRUE&lt;br /&gt;12 gt 3 FALSE !&lt;br /&gt;"" == "hello" TRUE ! (Warning)&lt;br /&gt;"" eq "hello" FALSE&lt;br /&gt;"hello" == "world" TRUE ! (Warning)&lt;br /&gt;"hello" eq "world" FALSE&lt;br /&gt;When reading from STDIN you can always expect a string&lt;br /&gt; 16&lt;br /&gt;Chapter 5. Scalars&lt;br /&gt;Example 5-12. examples/scalars/is_empty_string.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my $input = &lt;STDIN&gt;;&lt;br /&gt;chomp $input;&lt;br /&gt;if ($input == "") { # wrong! use eq&lt;br /&gt;# empty string&lt;br /&gt;}&lt;br /&gt;5.15. Boolean expressions (logical operators)&lt;br /&gt;Table 5-3. Logical operators&lt;br /&gt;and &amp;&amp;&lt;br /&gt;or ||&lt;br /&gt;not !&lt;br /&gt;if (COND and COND) {&lt;br /&gt;}&lt;br /&gt;if (COND or COND) {&lt;br /&gt;}&lt;br /&gt;if (not COND) {&lt;br /&gt;}&lt;br /&gt;See also perldoc perlop for precedence and associativity tables and/or use () to define the order of&lt;br /&gt;evaluation.&lt;br /&gt;5.16. TRUE and FALSE&lt;br /&gt;The FALSE values:&lt;br /&gt;undef&lt;br /&gt;""&lt;br /&gt;0 0.0 00000 0e+10&lt;br /&gt;"0"&lt;br /&gt;Other values such as the following are TRUE&lt;br /&gt;1&lt;br /&gt;"00"&lt;br /&gt; 17&lt;br /&gt;Chapter 5. Scalars&lt;br /&gt;"0\n"&lt;br /&gt;if ($z) {&lt;br /&gt;# $z is true&lt;br /&gt;}&lt;br /&gt;if (defined $x) {&lt;br /&gt;# $x is defined (not undef)&lt;br /&gt;}&lt;br /&gt;5.17. Your Salary is in Danger - Short-Circuit&lt;br /&gt;If perl already knows the final value of a boolean expression after computing&lt;br /&gt;only part of it, perl will NOT calculate the rest of the expression:&lt;br /&gt;if ($my_money &gt; 1_000_000 or $my_salary &gt; 10_000) {&lt;br /&gt;# I can live well&lt;br /&gt;}&lt;br /&gt;if ($my_money &gt; 1_000_000 or $my_salary++ &gt; 10_000) {&lt;br /&gt;# I can live well&lt;br /&gt;}&lt;br /&gt;5.18. String functions&lt;br /&gt;• length STRING - number of characters&lt;br /&gt;• lc STRING - lower case&lt;br /&gt;• uc STRING - upper case&lt;br /&gt;• index STRING, SUBSTRING - the location of a substring given its content&lt;br /&gt;Example 5-13. examples/scalars/string_functions.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my $s = "The black cat jumped from the green tree";&lt;br /&gt;print index $s, "ac"; # 6&lt;br /&gt;print "\n";&lt;br /&gt;print index $s, "e"; # 2&lt;br /&gt;print "\n";&lt;br /&gt;print index $s, "e", 3; # 18&lt;br /&gt; 18&lt;br /&gt;Chapter 5. Scalars&lt;br /&gt;print "\n";&lt;br /&gt;print index $s, "dog"; # -1&lt;br /&gt;print "\n";&lt;br /&gt;print rindex $s, "e"; # 39&lt;br /&gt;print "\n";&lt;br /&gt;print rindex $s, "e", 38; # 38&lt;br /&gt;print "\n";&lt;br /&gt;print rindex $s, "e", 37; # 33&lt;br /&gt;print "\n";&lt;br /&gt;5.19. String functions&lt;br /&gt;substr STRING, OFFSET, LENGTH - the content of a substring given its location&lt;br /&gt;Example 5-14. examples/scalars/string_functions_substr.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my $s = "The black cat climbed the green tree";&lt;br /&gt;my $z;&lt;br /&gt;$z = substr $s, 4, 5; # $z = black&lt;br /&gt;print "$z\n";&lt;br /&gt;$z = substr $s, 4, -11; # $z = black cat climbed the&lt;br /&gt;print "$z\n";&lt;br /&gt;$z = substr $s, 14; # $z = climbed the green tree&lt;br /&gt;print "$z\n";&lt;br /&gt;$z = substr $s, -4; # $z = tree&lt;br /&gt;print "$z\n";&lt;br /&gt;$z = substr $s, -4, 2; # $z = tr&lt;br /&gt;print "$z\n";&lt;br /&gt;$z = substr $s, 14, 7, "jumped from"; # $z = climbed&lt;br /&gt;print "$z\n";&lt;br /&gt;print "$s\n"; # $s = The black cat jumped from the green tree&lt;br /&gt;5.20. Strings - Double quoted&lt;br /&gt;print "normal string"; # normal string&lt;br /&gt;print "two\nlines"; # two&lt;br /&gt;# lines&lt;br /&gt;print "another ’string’"; # another ’string’&lt;br /&gt;my $name = "Foo";&lt;br /&gt; 19&lt;br /&gt;Chapter 5. Scalars&lt;br /&gt;print "Hello $name, how are you?"; # Hello Foo, how are you?&lt;br /&gt;print "His "real" name is Foo"; # ERROR&lt;br /&gt;print "His \"real\" name is Foo"; # His "real" name is Foo&lt;br /&gt;print "His \"real\" name is \"$name\""; # His "real" name is "Foo"&lt;br /&gt;print qq(His "real" name is "$name"); # His "real" name is "Foo"&lt;br /&gt;print qq(His "real" name is ($name)); # His "real" name is (Foo)&lt;br /&gt;print qq{His "real" name is ($name)}; # His "real" name is (Foo)&lt;br /&gt;In double quoted strings you can use the following:&lt;br /&gt;Backslash escapes sequences like \n \t&lt;br /&gt;see in perldoc perlop&lt;br /&gt;Variable interpolation&lt;br /&gt;5.21. Strings - Single quoted&lt;br /&gt;print ’one string’; # one string&lt;br /&gt;print ’a\n’; # a\n&lt;br /&gt;print ’a $name’; # a $name&lt;br /&gt;print ’another "string"’; # another "string"&lt;br /&gt;There are only two special characters in this kind of string the ’&lt;br /&gt;and the \ at the end of the string&lt;br /&gt;print ’a’b’; # ERROR - perl will see the string ’a’&lt;br /&gt;# and something attached to it&lt;br /&gt;print ’a\’b’; # a’b&lt;br /&gt;print ’ab\’; # ERROR - perl will not see the closing ’&lt;br /&gt;# as it will think it was escaped&lt;br /&gt;print ’ab\\’; # ab\&lt;br /&gt;print q(His "variable" name ’$name’\n); # His "variable" name is ’$name’\n&lt;br /&gt;5.22. Scope of variables&lt;br /&gt;Variables defined within a block {} are hiding more global&lt;br /&gt;variables with the same name.&lt;br /&gt;They are descrutced when leaving the block.&lt;br /&gt; 20&lt;br /&gt;Chapter 5. Scalars&lt;br /&gt;Example 5-15. examples/scalars/scope.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my $fname = "Foo";&lt;br /&gt;my $lname = "Bar";&lt;br /&gt;print "$fname\n"; # Foo&lt;br /&gt;print "$lname\n"; # Bar&lt;br /&gt;{&lt;br /&gt;my $email = ’foo@bar.com’;&lt;br /&gt;print "$email\n"; # foo@bar.com&lt;br /&gt;print "$fname\n"; # Foo&lt;br /&gt;print "$lname\n"; # Bar&lt;br /&gt;my $lname = "Moo";&lt;br /&gt;print "$lname\n"; # Moo&lt;br /&gt;}&lt;br /&gt;# $email does not exists&lt;br /&gt;print "$fname\n"; # Foo&lt;br /&gt;print "$lname\n"; # Bar&lt;br /&gt;5.23. Random numbers&lt;br /&gt;Example 5-16. examples/scalars/random.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my $num = rand(); # returns a random number: 0 &lt;= NUMBER &lt; 1&lt;br /&gt;my $n = rand(100); # returns a number: 0 &lt;= NUMBER &lt; 100&lt;br /&gt;my $i = int(3.12); # returns the whole part of the number (3 in this case)&lt;br /&gt;my $number = int(rand(100)); # returns a whole number: 0 &lt;= NUMBER &lt; 100&lt;br /&gt;5.24. Exercises: Simple Calcualtor&lt;br /&gt;Write a script that will ask for a number, an operator (+,*,-,/)&lt;br /&gt;and another number. Compute the result and print it out.&lt;br /&gt; 21&lt;br /&gt;Chapter 5. Scalars&lt;br /&gt;5.25. Number Guessing game&lt;br /&gt;Using the rand() function the computer thinks about a number.&lt;br /&gt;The user has to guess the number. After the user types in&lt;br /&gt;his guess the computer tells if this was bigger or smaller than&lt;br /&gt;the number it generated.&lt;br /&gt;At this point there is no need to allow the user to guess several times.&lt;br /&gt;5.26. Solution: Simple Calulator&lt;br /&gt;Example 5-17. examples/scalars/basic_calculator.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;print "Type in 2 numbers and an operator and I’ll print the results\n\n";&lt;br /&gt;print "First number: ";&lt;br /&gt;my $first = &lt;STDIN&gt;;&lt;br /&gt;chomp($first);&lt;br /&gt;print "Second number: ";&lt;br /&gt;my $other = &lt;STDIN&gt;;&lt;br /&gt;chomp($other);&lt;br /&gt;print "The operator: ";&lt;br /&gt;my $oper = &lt;STDIN&gt;;&lt;br /&gt;chomp($oper);&lt;br /&gt;my $result;&lt;br /&gt;if ($oper eq "+") { $result = $first + $other; }&lt;br /&gt;if ($oper eq "-") { $result = $first - $other; }&lt;br /&gt;if ($oper eq "*") { $result = $first * $other; }&lt;br /&gt;if ($oper eq "/") {&lt;br /&gt;if ($other == 0) {&lt;br /&gt;print "\nCannot divide by 0\n";&lt;br /&gt;$result = "ERROR";&lt;br /&gt;} else {&lt;br /&gt;$result = $first / $other;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;print "\nResult of $first $oper $other = $result\n";&lt;br /&gt;# What if the given operator is not one of the 4 ?&lt;br /&gt; 22&lt;br /&gt;Chapter 5. Scalars&lt;br /&gt;5.27. Solution: Simple Calulator (using eval)&lt;br /&gt;Example 5-18. examples/scalars/basic_calculator_eval.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;print "Type in 2 numbers and an operator and I’ll print the results\n\n";&lt;br /&gt;print "First number: ";&lt;br /&gt;my $first = &lt;STDIN&gt;;&lt;br /&gt;chomp($first);&lt;br /&gt;print "Second number: ";&lt;br /&gt;my $other = &lt;STDIN&gt;;&lt;br /&gt;chomp($other);&lt;br /&gt;print "The operator: ";&lt;br /&gt;my $oper = &lt;STDIN&gt;;&lt;br /&gt;chomp($oper);&lt;br /&gt;my $result = eval "$first $oper $other";&lt;br /&gt;print "\nResult of $first $oper $other = $result\n";&lt;br /&gt; 23&lt;br /&gt;Chapter 6. Files&lt;br /&gt;6.1. die, warn, exit&lt;br /&gt;exit() - exits from the program&lt;br /&gt;warn() - writes to STDERR&lt;br /&gt;die() - writes to STDERR and exits from the program&lt;br /&gt;warn "This is a warning";&lt;br /&gt;This is a warning at script.pl line 132.&lt;br /&gt;If no \n at the end of the string both warn and die add the&lt;br /&gt;name of file and line number and possibly the chunk of the input.&lt;br /&gt;6.2. Opening file for reading&lt;br /&gt;While working over most of the operating systems today, no program can&lt;br /&gt;access a file directly. This is in order to allow the Operaring System&lt;br /&gt;to apply user rights.&lt;br /&gt;Before you can read from a file you have to ask the Operating System to "open"&lt;br /&gt;it for you. When opening a file you provide a variable that will become your&lt;br /&gt;handle to the opened file. It is called a filehandle.&lt;br /&gt;my $filename = "input.txt";&lt;br /&gt;open(my $fh, "&lt;", $filename);&lt;br /&gt;close $fh;&lt;br /&gt;6.3. Opening a file&lt;br /&gt;my $filename = "some_filename");&lt;br /&gt;open(my $fhb, "&lt;", $filename); # read&lt;br /&gt;open(my $fhc, "&gt;", $filename); # write&lt;br /&gt;open(my $fhd, "&gt;&gt;", $filename); # append&lt;br /&gt;open(my $fhe, "+&lt;", $filename); # read and write&lt;br /&gt;6.4. Opening a file - error handling&lt;br /&gt;• $! - error message from the Operating system&lt;br /&gt;24&lt;br /&gt;Chapter 6. Files&lt;br /&gt;Example 6-1. examples/files/open_with_if.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my $filename = "input.txt";&lt;br /&gt;if (open my $in, "&lt;", $filename) {&lt;br /&gt;# do your thing here&lt;br /&gt;# no need to explicitly close the file&lt;br /&gt;} else {&lt;br /&gt;warn "Could not open file ’$filename’. $!";&lt;br /&gt;}&lt;br /&gt;# here the $in filehandle is not accessible anymore&lt;br /&gt;A more Perlish way to open a file and exit with error message if you could not open the file:&lt;br /&gt;Example 6-2. examples/files/open_with_die.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my $filename = "input.txt";&lt;br /&gt;open(my $fh, "&lt;", $filename) or die "Could not open file ’$filename’. $!";&lt;br /&gt;# do your thing here&lt;br /&gt;close $fh;&lt;br /&gt;6.5. Opening a missing file&lt;br /&gt;Example 6-3. examples/files/open_missing_file.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;if (open my $fh, ’&lt;’, "nosuch") {&lt;br /&gt;# should do here something&lt;br /&gt;} else {&lt;br /&gt;warn $!;&lt;br /&gt;}&lt;br /&gt;The error message we get:&lt;br /&gt;No such file or directory at examples/files/open_missing_file.pl line 7.&lt;br /&gt; 25&lt;br /&gt;Chapter 6. Files&lt;br /&gt;6.6. Read one line from a file&lt;br /&gt;Example 6-4. examples/files/read_line.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;# Reading a line from a file (or rather from a filehandle)&lt;br /&gt;my $filename = "input.txt";&lt;br /&gt;if (open my $data, "&lt;", $filename) {&lt;br /&gt;my $line = &lt;$data&gt;;&lt;br /&gt;print $line;&lt;br /&gt;} else {&lt;br /&gt;warn "Could not open file ’$filename’: $!";&lt;br /&gt;}&lt;br /&gt;6.7. Process an entire file line by line (while, cat)&lt;br /&gt;• while - executes as long as there is something in $line, as long as there are lines in the file&lt;br /&gt;• Loop over file (name hardcoded) and print every line (UNIX cat)&lt;br /&gt;Example 6-5. examples/files/cat.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my $filename = "input.txt";&lt;br /&gt;open(my $fh, "&lt;", $filename) or die "Could not open ’$filename’\n";&lt;br /&gt;while (my $line = &lt;$fh&gt;) {&lt;br /&gt;print $line;&lt;br /&gt;}&lt;br /&gt;Instead of printing the line you could do anything with it.&lt;br /&gt;6.8. Write to a file&lt;br /&gt;Example 6-6. examples/files/write_file.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my $filename = "report.txt";&lt;br /&gt; 26&lt;br /&gt;Chapter 6. Files&lt;br /&gt;open my $fh, ’&gt;’, $filename or die "Could not open file ’$filename’ $!";&lt;br /&gt;print $fh "Report by: Foo Bar\n";&lt;br /&gt;print $fh "-" x 20;&lt;br /&gt;print $fh "\n";&lt;br /&gt;6.9. Sum of numbers in a file&lt;br /&gt;Example 6-7. examples/files/count_sum_write.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;# given a file with a number on each row, print the sum of the numbers&lt;br /&gt;my $sum = 0;&lt;br /&gt;my $filename = "numbers.txt";&lt;br /&gt;open(my $fh, "&lt;", $filename) or die "Could not open ’$filename’\n";&lt;br /&gt;while (my $line = &lt;$fh&gt;) {&lt;br /&gt;$sum += $line;&lt;br /&gt;}&lt;br /&gt;print "The total value is $sum\n";&lt;br /&gt;6.10. Analyze the Apache log file&lt;br /&gt;Example 6-8. examples/files/apache_access.log&lt;br /&gt;127.0.0.1 - - [10/Apr/2007:10:39:11 +0300] "GET / HTTP/1.1" 500 606 "-" "Mozilla/5.0 (X11; U; 127.0.0.1 - - [10/Apr/2007:10:39:11 +0300] "GET /favicon.ico HTTP/1.1" 200 766 "-" "Mozilla/139.12.0.2 - - [10/Apr/2007:10:40:54 +0300] "GET / HTTP/1.1" 500 612 "-" "Mozilla/5.0 (X11; 139.12.0.2 - - [10/Apr/2007:10:40:54 +0300] "GET /favicon.ico HTTP/1.1" 200 766 "-" "Mozilla/127.0.0.1 - - [10/Apr/2007:10:53:10 +0300] "GET / HTTP/1.1" 500 612 "-" "Mozilla/5.0 (X11; U; 127.0.0.1 - - [10/Apr/2007:10:54:08 +0300] "GET / HTTP/1.0" 200 3700 "-" "Mozilla/5.0 (X11; 127.0.0.1 - - [10/Apr/2007:10:54:08 +0300] "GET /style.css HTTP/1.1" 200 614 "http://pti.local/" 127.0.0.1 - - [10/Apr/2007:10:54:08 +0300] "GET /img/pti-round.jpg HTTP/1.1" 200 17524 "http://127.0.0.1 - - [10/Apr/2007:10:54:21 +0300] "GET /unix_sysadmin.html HTTP/1.1" 200 3880 "http://217.0.22.3 - - [10/Apr/2007:10:54:51 +0300] "GET / HTTP/1.1" 200 34 "-" "Mozilla/5.0 (X11; U; 217.0.22.3 - - [10/Apr/2007:10:54:51 +0300] "GET /favicon.ico HTTP/1.1" 200 11514 "-" "Mozilla/217.0.22.3 - - [10/Apr/2007:10:54:53 +0300] "GET /cgi/pti.pl HTTP/1.1" 500 617 "http://contact.127.0.0.1 - - [10/Apr/2007:10:54:08 +0300] "GET / HTTP/0.9" 200 3700 "-" "Mozilla/5.0 (X11; 217.0.22.3 - - [10/Apr/2007:10:58:27 +0300] "GET / HTTP/1.1" 200 3700 "-" "Mozilla/5.0 (X11; 217.0.22.3 - - [10/Apr/2007:10:58:34 +0300] "GET /unix_sysadmin.html HTTP/1.1" 200 3880 "http://217.0.22.3 - - [10/Apr/2007:10:58:45 +0300] "GET /talks/Fundamentals/read-excel-file.html HTTP/ 27&lt;br /&gt;Chapter 6. Files&lt;br /&gt;Example 6-9. examples/files/apache_log_hosts.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my $file = "examples/files/apache_access.log";&lt;br /&gt;open my $fh, ’&lt;’, $file or die "Could not open ’$file’: $!";&lt;br /&gt;my $good;&lt;br /&gt;my $bad;&lt;br /&gt;while (my $line = &lt;$fh&gt;) {&lt;br /&gt;chomp $line;&lt;br /&gt;my $length = index ($line, " ");&lt;br /&gt;my $ip = substr($line, 0, $length);&lt;br /&gt;if ($ip eq "127.0.0.1") {&lt;br /&gt;$good++;&lt;br /&gt;} else {&lt;br /&gt;$bad++;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;print "$good $bad\n";&lt;br /&gt;6.11. Open files in the old way&lt;br /&gt;In old version of perl (before 5.6) we could not use scalar variabsles as file&lt;br /&gt;handles so we used uppercase letters such as XYZ or INPUT, QQRQ or FILEHANDLE.&lt;br /&gt;Also the function had only 2 parameters.&lt;br /&gt;Example 6-10. examples/files/open_file_old.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my $filename = "data.txt";&lt;br /&gt;open(FH, $filename);&lt;br /&gt;my $line = &lt;FH&gt;;&lt;br /&gt;close FH;&lt;br /&gt;open(FH, "&gt;$filename");&lt;br /&gt;print FH "data";&lt;br /&gt;close FH;&lt;br /&gt;Security problems.&lt;br /&gt; 28&lt;br /&gt;Chapter 6. Files&lt;br /&gt;Being global, difficult to pass as parameter to functions.&lt;br /&gt;6.12. Exercise: Add more statistics&lt;br /&gt;Take the script from the previous example (count_sum_write.pl)&lt;br /&gt;and in addition to the sum of the numbers print also&lt;br /&gt;minimum&lt;br /&gt;maximum&lt;br /&gt;average&lt;br /&gt;median and standard deviation are probably too difficult for now.&lt;br /&gt;6.13. Exercise: Write report to file&lt;br /&gt;Take the exercise creating statistics of the numbers.txt file and&lt;br /&gt;write the results to the numbers.out file.&lt;br /&gt;minimum: -17&lt;br /&gt;maximum: 98&lt;br /&gt;total: 126&lt;br /&gt;count: 6&lt;br /&gt;average: 21&lt;br /&gt;You might need to look up the documentation of the printf&lt;br /&gt;in order to have align the columns.&lt;br /&gt;6.14. Exercise: Analyze Apache - number of successful&lt;br /&gt;hits&lt;br /&gt;In the Apache log file after the "GET something HTTP/1.1" part there is the&lt;br /&gt;result code of the requests. 200 is OK the rest might be some failure.&lt;br /&gt;Please create a report showing how many of the hits were successful (200)&lt;br /&gt;and how many were something else.&lt;br /&gt;Could you put all the lines in either of the categories?&lt;br /&gt; 29&lt;br /&gt;Chapter 6. Files&lt;br /&gt;6.15. Solution: Add more statistics&lt;br /&gt;Example 6-11. examples/files/statistics.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my $total = 0;&lt;br /&gt;my $count = 0;&lt;br /&gt;my $min;&lt;br /&gt;my $max;&lt;br /&gt;my $filename = "numbers.txt";&lt;br /&gt;open(my $fh, "&lt;", $filename) or die "Could not open ’$filename’\n";&lt;br /&gt;while (my $line = &lt;$fh&gt;) {&lt;br /&gt;chomp $line;&lt;br /&gt;$total += $line;&lt;br /&gt;if (not $count) {&lt;br /&gt;$min = $line;&lt;br /&gt;$max = $line;&lt;br /&gt;}&lt;br /&gt;$count++;&lt;br /&gt;if ($line &lt; $min) {&lt;br /&gt;$min = $line;&lt;br /&gt;}&lt;br /&gt;if ($line &gt; $max) {&lt;br /&gt;$max = $line;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;if (not defined $min) {&lt;br /&gt;print "No values were given\n";&lt;br /&gt;} else {&lt;br /&gt;print "Min: $min Max: $max Total: $total count: $count Average: ",&lt;br /&gt;$total / $count, "\n";&lt;br /&gt;}&lt;br /&gt;6.16. Solution: Analyze Apache - number of successful&lt;br /&gt;hits&lt;br /&gt;Example 6-12. examples/files/apache_log_result_code.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt; 30&lt;br /&gt;Chapter 6. Files&lt;br /&gt;my $file = "examples/files/apache_access.log";&lt;br /&gt;open my $fh, ’&lt;’, $file or die "Could not open ’$file’: $!";&lt;br /&gt;my $good = 0;&lt;br /&gt;my $bad = 0;&lt;br /&gt;my $ugly = 0;&lt;br /&gt;while (my $line = &lt;$fh&gt;) {&lt;br /&gt;chomp $line;&lt;br /&gt;my $request = q( HTTP/1.1" );&lt;br /&gt;my $start_request = index ($line, $request);&lt;br /&gt;my $result;&lt;br /&gt;if ($start_request &gt;= 0) {&lt;br /&gt;my $end_request = index($line, " ", $start_request + length($request));&lt;br /&gt;$result = substr($line, $start_request + length($request), $end_request-$start_request #print "$start_request, $end_request ’$result’\n";&lt;br /&gt;} else {&lt;br /&gt;my $request = q( HTTP/1.0" );&lt;br /&gt;my $start_request = index ($line, $request);&lt;br /&gt;if ($start_request &gt;= 0) {&lt;br /&gt;my $end_request = index($line, " ", $start_request + length($request));&lt;br /&gt;$result = substr($line, $start_request + length($request), $end_request-$start_request #print "$start_request, $end_request ’$result’\n";&lt;br /&gt;} else {&lt;br /&gt;#print "ERROR: Unrecognized Line: $line\n";&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;if (defined $result) {&lt;br /&gt;if ($result eq "200") {&lt;br /&gt;$good++;&lt;br /&gt;} else {&lt;br /&gt;$bad++;&lt;br /&gt;}&lt;br /&gt;} else {&lt;br /&gt;$ugly++;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;print "Good: $good\n";&lt;br /&gt;print "Bad: $bad\n";&lt;br /&gt;print "Ugly: $ugly\n";&lt;br /&gt;# Disclaimer: this is not an optimal solution.&lt;br /&gt;# We will see a much better one after learning functions, regular expressions&lt;br /&gt; 31&lt;br /&gt;Chapter 6. Files&lt;br /&gt;6.17. Solution: Write report to file&lt;br /&gt;Example 6-13. examples/files/write_report_to_file.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my $total = 0;&lt;br /&gt;my $count = 0;&lt;br /&gt;my $min;&lt;br /&gt;my $max;&lt;br /&gt;my $filename = "examples/files/numbers.txt";&lt;br /&gt;open(my $fh, "&lt;", $filename) or die "Could not open ’$filename’\n";&lt;br /&gt;while (my $line = &lt;$fh&gt;) {&lt;br /&gt;chomp $line;&lt;br /&gt;$total += $line;&lt;br /&gt;if (not $count) {&lt;br /&gt;$min = $line;&lt;br /&gt;$max = $line;&lt;br /&gt;}&lt;br /&gt;$count++;&lt;br /&gt;if ($line &lt; $min) {&lt;br /&gt;$min = $line;&lt;br /&gt;}&lt;br /&gt;if ($line &gt; $max) {&lt;br /&gt;$max = $line;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;open my $out, ’&gt;’, ’numbers.out’;&lt;br /&gt;if (not defined $min) {&lt;br /&gt;print $out "No values were given\n";&lt;br /&gt;} else {&lt;br /&gt;printf($out "Minimum: %5s\n", $min);&lt;br /&gt;printf($out "Maximum: %5s\n", $max);&lt;br /&gt;printf($out "Total: %5s\n", $total);&lt;br /&gt;printf($out "Count: %5s\n", $count);&lt;br /&gt;printf($out "Average: %5s\n", $total / $count);&lt;br /&gt;}&lt;br /&gt; 32&lt;br /&gt;Chapter 7. Lists and Arrays&lt;br /&gt;7.1. List Literals, list ranges&lt;br /&gt;Things in () separated by commas are called a list of things.&lt;br /&gt;A list is an ordered set of scalar values.&lt;br /&gt;Examples of lists:&lt;br /&gt;(1, 5.2, "apple") # 3 values&lt;br /&gt;(1,2,3,4,5,6,7,8,9,10) # nice but we are too lazy, so we write this:&lt;br /&gt;(1..10) # same as (1,2,3,4,5,6,7,8,9,10)&lt;br /&gt;(’a’..’z’) # all the lowercase letters&lt;br /&gt;("apple", "banana", "peach", "blueberry") # is the same as&lt;br /&gt;qw(apple banana peach blueberry) # quote word&lt;br /&gt;($x, $y, $z) # We can also use scalar variables as elements of a list&lt;br /&gt;7.2. List Assignment&lt;br /&gt;my ($x, $y, $z);&lt;br /&gt;($x, $y, $z) = (2, 3, 7); # nearly the same as $x=2; $y=3; $z=7;&lt;br /&gt;($x, $y) = (8, 1, 5); # ignore 5&lt;br /&gt;($x, $y, $z) = (3, 4); # $z will be undef&lt;br /&gt;A regular question on job interviews:&lt;br /&gt;How can we swap the values of 2 variables, let say $x and $y?&lt;br /&gt;7.3. loop over elements of list with foreach&lt;br /&gt;• list&lt;br /&gt;• foreach ITEM (LIST) {BLOCK}&lt;br /&gt;• my - in the foreach loop&lt;br /&gt;Example 7-1. examples/arrays/list_colors.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;33&lt;br /&gt;Chapter 7. Lists and Arrays&lt;br /&gt;foreach my $color ("Blue", "Yellow", "Brown", "White") {&lt;br /&gt;print "$color\n";&lt;br /&gt;}&lt;br /&gt;Blue&lt;br /&gt;Yellow&lt;br /&gt;Brown&lt;br /&gt;White&lt;br /&gt;7.4. Create an Array, loop over with foreach&lt;br /&gt;Example 7-2. examples/arrays/list_colors_array.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my @colors = ("Blue", "Yellow", "Brown", "White");&lt;br /&gt;print "@colors\n";&lt;br /&gt;foreach my $color (@colors) {&lt;br /&gt;print "$color\n";&lt;br /&gt;}&lt;br /&gt;Blue Yellow Brown White&lt;br /&gt;Blue&lt;br /&gt;Yellow&lt;br /&gt;Brown&lt;br /&gt;White&lt;br /&gt;7.5. Array Assignment&lt;br /&gt;You can also mix the variables on the right side and if there are arrays on the right side the whole thing&lt;br /&gt;becomes one flat array !&lt;br /&gt;my $owner = "Moose";&lt;br /&gt;my @tenants = qw(Foo Bar);&lt;br /&gt;my @people = ($owner, ’Baz’, @tenants); # Moose Baz Foo Bar&lt;br /&gt;my ($x, @y, @z);&lt;br /&gt;($x, @y) = (1, 2, 3, 4); # $x is 1; @y is (2, 3, 4)&lt;br /&gt;($x, @y, @z) = (1, 2, 3, 4); # $x is 1; @y is (2, 3, 4) @z is empty: ()&lt;br /&gt;@y = (); # Emptying an array&lt;br /&gt; 34&lt;br /&gt;Chapter 7. Lists and Arrays&lt;br /&gt;7.6. foreach loop on numbers&lt;br /&gt;foreach my $i (1..10) {&lt;br /&gt;print "$i\n";&lt;br /&gt;}&lt;br /&gt;1&lt;br /&gt;2&lt;br /&gt;3&lt;br /&gt;4&lt;br /&gt;5&lt;br /&gt;6&lt;br /&gt;7&lt;br /&gt;8&lt;br /&gt;9&lt;br /&gt;10&lt;br /&gt;7.7. Array index (menu)&lt;br /&gt;• $#array - the largest index&lt;br /&gt;• $array[1] - array elements are scalar&lt;br /&gt;Example 7-3. examples/arrays/color_menu.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my $color;&lt;br /&gt;my @colors = ("Blue", "Yellow", "Brown", "White");&lt;br /&gt;print "Please select a number:\n";&lt;br /&gt;foreach my $i (0..$#colors) {&lt;br /&gt;print "$i) $colors[$i]\n";&lt;br /&gt;}&lt;br /&gt;my $num = &lt;STDIN&gt;;&lt;br /&gt;chomp($num);&lt;br /&gt;if (defined $colors[$num]) {&lt;br /&gt;$color = $colors[$num];&lt;br /&gt;} else {&lt;br /&gt;print "Bad selection\n";&lt;br /&gt;exit;&lt;br /&gt;}&lt;br /&gt;print "The selected color is $color\n";&lt;br /&gt; 35&lt;br /&gt;Chapter 7. Lists and Arrays&lt;br /&gt;7.8. Command line parameters&lt;br /&gt;• @ARGV - all the arguments on the command line&lt;br /&gt;• $ARGV[0] - the first argument&lt;br /&gt;• $0 - name of the program&lt;br /&gt;• perl read_argv.pl blue&lt;br /&gt;Example 7-4. examples/arrays/read_argv.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my $color;&lt;br /&gt;if (defined $ARGV[0]) {&lt;br /&gt;$color = $ARGV[0];&lt;br /&gt;}&lt;br /&gt;my @colors = ("Blue", "Yellow", "Brown", "White");&lt;br /&gt;if (not defined $color) {&lt;br /&gt;print "Please select a number:\n";&lt;br /&gt;foreach my $i (0..$#colors) {&lt;br /&gt;print "$i) $colors[$i]\n";&lt;br /&gt;}&lt;br /&gt;my $num = &lt;STDIN&gt;;&lt;br /&gt;chomp($num);&lt;br /&gt;if (defined $colors[$num]) {&lt;br /&gt;$color = $colors[$num];&lt;br /&gt;} else {&lt;br /&gt;print "Bad selection\n";&lt;br /&gt;exit;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;print "The selected color is $color\n";&lt;br /&gt;7.9. Process command line parameters, use modules&lt;br /&gt;• use Module;&lt;br /&gt;• scalar reference&lt;br /&gt;Example 7-5. examples/arrays/process_command_line.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt; 36&lt;br /&gt;Chapter 7. Lists and Arrays&lt;br /&gt;use Getopt::Long qw(GetOptions);&lt;br /&gt;my $color;&lt;br /&gt;GetOptions("color=s" =&gt; \$color) or die "Usage: $0 [--color COLOR]\n";&lt;br /&gt;my @colors = ("Blue", "Yellow", "Brown", "White");&lt;br /&gt;if (not defined $color) {&lt;br /&gt;print "Please select a number:\n";&lt;br /&gt;foreach my $i (0..$#colors) {&lt;br /&gt;print "$i) $colors[$i]\n";&lt;br /&gt;}&lt;br /&gt;my $num = &lt;STDIN&gt;;&lt;br /&gt;chomp($num);&lt;br /&gt;if (defined $colors[$num]) {&lt;br /&gt;$color = $colors[$num];&lt;br /&gt;} else {&lt;br /&gt;print "Bad selection\n";&lt;br /&gt;exit;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;print "The selected color is $color\n";&lt;br /&gt;7.10. Module documentation&lt;br /&gt;perldoc Getopt::Long&lt;br /&gt;http://perldoc.perl.org/Getopt/Long.html&lt;br /&gt;perldoc Cwd&lt;br /&gt;http://perldoc.perl.org/Cwd.html&lt;br /&gt;7.11. process csv file&lt;br /&gt;• split&lt;br /&gt;Example 7-6. examples/arrays/process_csv_file.csv&lt;br /&gt;Foo,Bar,10,home&lt;br /&gt;Orgo,Morgo,7,away&lt;br /&gt;Big,Shrek,100,US&lt;br /&gt;Small,Fiona,9,tower&lt;br /&gt; 37&lt;br /&gt;Chapter 7. Lists and Arrays&lt;br /&gt;Example 7-7. examples/arrays/process_csv_file.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my $file = ’process_csv_file.csv’;&lt;br /&gt;if (defined $ARGV[0]) {&lt;br /&gt;$file = $ARGV[0];&lt;br /&gt;}&lt;br /&gt;my $sum = 0;&lt;br /&gt;open(my $data, ’&lt;’, $file) or die "Could not open ’$file’\n";&lt;br /&gt;while (my $line = &lt;$data&gt;) {&lt;br /&gt;chomp $line;&lt;br /&gt;my @columns = split ",", $line;&lt;br /&gt;$sum += $columns[2];&lt;br /&gt;}&lt;br /&gt;print "$sum\n";&lt;br /&gt;7.12. process csv file (short version)&lt;br /&gt;Example 7-8. examples/arrays/process_csv_file_short.pl&lt;br /&gt;while (&lt;&gt;) {&lt;br /&gt;$sum += (split ",")[2];&lt;br /&gt;}&lt;br /&gt;print "$sum\n";&lt;br /&gt;Use the following command to run the script:&lt;br /&gt;perl examples/arrays/process_csv_file_short.pl examples/arrays/process_csv_file.csv&lt;br /&gt;See also the oneliners&lt;br /&gt;7.13. process csv file using Text::CSV_XS&lt;br /&gt;What if there is a field called: "Foo, Bar" ?&lt;br /&gt;Example 7-9. examples/arrays/process_csv_file_module.csv&lt;br /&gt;Foo,Bar ,10,home&lt;br /&gt;Orgo,"Morgo, Hapci",7,away&lt;br /&gt;Big,Shrek,100,US&lt;br /&gt;Small,Fiona,9,tower&lt;br /&gt; 38&lt;br /&gt;Chapter 7. Lists and Arrays&lt;br /&gt;Example 7-10. examples/arrays/process_csv_file_module.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;use Text::CSV_XS;&lt;br /&gt;my $csv = Text::CSV_XS-&gt;new();&lt;br /&gt;my $file = ’process_csv_file_module.csv’;&lt;br /&gt;if (defined $ARGV[0]) {&lt;br /&gt;$file = $ARGV[0];&lt;br /&gt;}&lt;br /&gt;my $sum = 0;&lt;br /&gt;open(my $data, ’&lt;’, $file) or die "Could not open ’$file’\n";&lt;br /&gt;while (my $line = &lt;$data&gt;) {&lt;br /&gt;chomp $line;&lt;br /&gt;if ($csv-&gt;parse($line)) {&lt;br /&gt;my @columns = $csv-&gt;fields();&lt;br /&gt;$sum += $columns[2];&lt;br /&gt;} else {&lt;br /&gt;warn "Line could not be parsed: $line\n";&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;print "$sum\n";&lt;br /&gt;7.14. Join&lt;br /&gt;my @fields = qw(Foo Bar foo@bar.com);&lt;br /&gt;my $line = join ";", @fields;&lt;br /&gt;print "$line\n"; # Foo;Bar;foo@bar.com&lt;br /&gt;7.15. Exercise: improve the color selector&lt;br /&gt;Take the process_command_line.pl script improve in several ways:&lt;br /&gt;- Check if the value given on the command line is indeed one&lt;br /&gt;of the possible values and don’t let other colors pass.&lt;br /&gt;- Allow a --force flag that will disregard the previously implemented restriction.&lt;br /&gt;- Read the names of the colors from a file called colors.txt&lt;br /&gt;- Let the user pass the name of the color file using the --filename FILENAME option.&lt;br /&gt; 39&lt;br /&gt;Chapter 7. Lists and Arrays&lt;br /&gt;7.16. Improve the Number Guessing game from the&lt;br /&gt;earlier chapter&lt;br /&gt;Let the user guess several times (with responses each time) till he finds&lt;br /&gt;the hidden number.&lt;br /&gt;Allow the user to type&lt;br /&gt;n - skip this game and start a new one&lt;br /&gt;s - show the hidden value&lt;br /&gt;x - exit&lt;br /&gt;Now I can tell you that what you have is actually a 1 dimensional space fight&lt;br /&gt;and you are trying to guess the distance of the enemy space ship.&lt;br /&gt;As it is not a sitting duck, after every shot the spaceship can randomly move +2-2.&lt;br /&gt;For trainng purposes you might want to limit the outer spaces to 0-100.&lt;br /&gt;Make sure the enemy does not wander off the training field.&lt;br /&gt;Give warning if the user shoots out of space.&lt;br /&gt;Keep track of the minimum and maximum number of hits (in a file).&lt;br /&gt;7.17. Solution: improved color selector&lt;br /&gt;Example 7-11. examples/arrays/color_selector.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;use Getopt::Long qw(GetOptions);&lt;br /&gt;my $color;&lt;br /&gt;my $filename = "examples/colors.txt";&lt;br /&gt;my $force;&lt;br /&gt;GetOptions(&lt;br /&gt;"color=s" =&gt; \$color,&lt;br /&gt;"filename=s" =&gt; \$filename,&lt;br /&gt;"force" =&gt; \$force,&lt;br /&gt;) or exit;&lt;br /&gt;open(my $fh, "&lt;", $filename)&lt;br /&gt;or die "Could not open ’$filename’ for reading: $!";&lt;br /&gt;my @colors;&lt;br /&gt;while (my $color = &lt;$fh&gt;) {&lt;br /&gt;chomp $color;&lt;br /&gt; 40&lt;br /&gt;Chapter 7. Lists and Arrays&lt;br /&gt;@colors = (@colors, $color);&lt;br /&gt;}&lt;br /&gt;# we will have a much better solution than the above 5 lines&lt;br /&gt;# but we have not learned it yet&lt;br /&gt;if ($color and not $force) {&lt;br /&gt;my $valid_color;&lt;br /&gt;foreach my $c (@colors) {&lt;br /&gt;if ($c eq $color) {&lt;br /&gt;$valid_color = 1;&lt;br /&gt;next;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;if (not $valid_color) {&lt;br /&gt;print "The color ’$color’ is not valid.\n";&lt;br /&gt;$color = ”;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;if (not $color) {&lt;br /&gt;print "Please select a number:\n";&lt;br /&gt;foreach my $i (0..$#colors) {&lt;br /&gt;print "$i) $colors[$i]\n";&lt;br /&gt;}&lt;br /&gt;my $num = &lt;STDIN&gt;;&lt;br /&gt;chomp($num);&lt;br /&gt;if (defined $colors[$num]) {&lt;br /&gt;$color = $colors[$num];&lt;br /&gt;} else {&lt;br /&gt;print "Bad selection\n";&lt;br /&gt;exit;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;print "The selected color is $color\n";&lt;br /&gt; 41&lt;br /&gt;Chapter 8. Advanced Arrays&lt;br /&gt;8.1. The year 19100&lt;br /&gt;First, let’s talk about time.&lt;br /&gt;$t = time(); # 1021924103&lt;br /&gt;# returns a 10 digit long number,&lt;br /&gt;# the number of seconds since 00:00:00 UTC, January 1, 1970&lt;br /&gt;$x = localtime($t); # returns a string like Thu Feb 30 14:15:53 2002&lt;br /&gt;$z = localtime(); # returns the string for the current time&lt;br /&gt;$z = localtime(time - 60*60*24*365);&lt;br /&gt;# returns the string for a year ago, same time, well almost&lt;br /&gt;@y = localtime($t); # an array of time values:&lt;br /&gt;# 53 15 14 30 1 102 4 61 0&lt;br /&gt;# the 9 values are the following:&lt;br /&gt;# 0 1 2 3 4 5 6 7 8 (the index)&lt;br /&gt;($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);&lt;br /&gt;# The localtime function is aware of what is on the left side of the = sign !!!!&lt;br /&gt;# OK but where does that 19100 come from ?&lt;br /&gt;$mon 0..11&lt;br /&gt;$min 0..59&lt;br /&gt;$sec 0..60&lt;br /&gt;$year YEAR-1900 # for example 2000-1900 = 100&lt;br /&gt;# but people used "19$year" instead of 1900 + $year&lt;br /&gt;# which is 19100 instead of 2000&lt;br /&gt;gmtime is the same just gives the time as it is in Greenwich.&lt;br /&gt;8.2. SCALAR and LIST Context&lt;br /&gt;my @a = ("zero", "one", "two", "three");&lt;br /&gt;my @b = @a; # LIST context&lt;br /&gt;my $c = @a; # SCALAR context&lt;br /&gt;if (@a) {&lt;br /&gt;}&lt;br /&gt;while (@a) {&lt;br /&gt;42&lt;br /&gt;Chapter 8. Advanced Arrays&lt;br /&gt;}&lt;br /&gt;8.3. Context Sensitivity&lt;br /&gt;Every operator creates a ’context’ let’s see a few examples&lt;br /&gt;Assignment to a scalar variable creates SCALAR context:&lt;br /&gt;$x = localtime();&lt;br /&gt;$x = @z;&lt;br /&gt;$x = SCALAR&lt;br /&gt;Assignment to an array creates LIST contex:&lt;br /&gt;@y = localtime();&lt;br /&gt;@y = @z;&lt;br /&gt;@y = LIST&lt;br /&gt;# Expressions providing SCALAR context&lt;br /&gt;$x = SCALAR;&lt;br /&gt;$y[3] = SCALAR;&lt;br /&gt;8 + SCALAR&lt;br /&gt;"Foo: " . SCALAR&lt;br /&gt;if (SCALAR) { ... }&lt;br /&gt;while (SCALAR) { ... }&lt;br /&gt;scalar(SCALAR)&lt;br /&gt;# Expressions providing LIST context:&lt;br /&gt;@a = LIST;&lt;br /&gt;($x, $y) = LIST;&lt;br /&gt;($x) = LIST;&lt;br /&gt;foreach $x (LIST) {...}&lt;br /&gt;join ";", LIST&lt;br /&gt;print LIST&lt;br /&gt;# example&lt;br /&gt;@a = qw(One Two Three);&lt;br /&gt;print @a; # OneTwoThree" print LIST&lt;br /&gt;print 0+@a; # 3 SCALAR + SCALAR&lt;br /&gt;print scalar(@a); # 3 scalar(SCALAR)&lt;br /&gt;see also perldoc -f function-name&lt;br /&gt;8.4. Filehandle in scalar and list context&lt;br /&gt;Example 8-1. examples/arrays/filehandle_in_context.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt; 43&lt;br /&gt;Chapter 8. Advanced Arrays&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my $file = "numbers.txt";&lt;br /&gt;open(my $fh, ’&lt;’, $file) or die "Could not open ’$file’";&lt;br /&gt;# reading in SCALAR context (line by line) and processing each line&lt;br /&gt;while (my $row = &lt;$fh&gt;) {&lt;br /&gt;chomp $row;&lt;br /&gt;print "READ: $row\n";&lt;br /&gt;}&lt;br /&gt;open (my $other_fh, ’&lt;’, $file) or die "Could not open ’$file’";&lt;br /&gt;# reading in LIST context all the lines at once&lt;br /&gt;my @rows = &lt;$other_fh&gt;;&lt;br /&gt;chomp @rows;&lt;br /&gt;print "READ " . @rows . " lines\n";&lt;br /&gt;8.5. slurp mode&lt;br /&gt;Example 8-2. examples/arrays/slurp.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my $file = "numbers.txt";&lt;br /&gt;# slurp mode&lt;br /&gt;my $all;&lt;br /&gt;{&lt;br /&gt;open(my $fh, ’&lt;’, $file) or die "Could not open ’$file’\n";&lt;br /&gt;local $/ = undef;&lt;br /&gt;$all = &lt;$fh&gt;;&lt;br /&gt;}&lt;br /&gt;8.6. File::Slurp&lt;br /&gt;Example 8-3. examples/arrays/file_slurp.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;use File::Slurp qw(slurp);&lt;br /&gt; 44&lt;br /&gt;Chapter 8. Advanced Arrays&lt;br /&gt;my $filename = shift or die "Usage: $0 FILENAME\n";&lt;br /&gt;my $text = slurp($filename);&lt;br /&gt;8.7. pop, push&lt;br /&gt;There are several functions working on arrays:&lt;br /&gt;pop and push implement a LIFO stack.&lt;br /&gt;pop fetches the last element of the array&lt;br /&gt;returns that value and the array becomes one shorter&lt;br /&gt;if the array was empty pop returns undef&lt;br /&gt;LAST = pop ARRAY;&lt;br /&gt;push is the opposite of pop it adds element(s) to the end of the array&lt;br /&gt;It returns number of elements after the push.&lt;br /&gt;PUSH ARRAY, SCALAR, ... (more SCALARs);&lt;br /&gt;Example:&lt;br /&gt;Example 8-4. examples/arrays/pop_push.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my @names = ("Foo", "Bar", "Baz");&lt;br /&gt;my $last_name = pop @names;&lt;br /&gt;print "$last_name\n"; # Baz&lt;br /&gt;print "@names\n"; # Foo Bar&lt;br /&gt;push @names, "Moo";&lt;br /&gt;print "@names\n"; # Foo Bar Moo&lt;br /&gt;8.8. stack (pop, push)&lt;br /&gt;Example 8-5. examples/arrays/reverse_polish_calculator.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt; 45&lt;br /&gt;Chapter 8. Advanced Arrays&lt;br /&gt;use warnings;&lt;br /&gt;my @stack;&lt;br /&gt;while (1) {&lt;br /&gt;print ’$ ’;&lt;br /&gt;my $in = &lt;STDIN&gt;;&lt;br /&gt;chomp $in;&lt;br /&gt;if ($in eq "x") { last; }&lt;br /&gt;if ($in eq "q") { last; }&lt;br /&gt;if ($in eq "c") {&lt;br /&gt;pop @stack;&lt;br /&gt;next;&lt;br /&gt;} # fetch the last value&lt;br /&gt;if ($in eq "*") {&lt;br /&gt;my $x = pop(@stack);&lt;br /&gt;my $y = pop(@stack);&lt;br /&gt;push(@stack, $x*$y);&lt;br /&gt;next;&lt;br /&gt;}&lt;br /&gt;if ($in eq "+") {&lt;br /&gt;my $x = pop(@stack);&lt;br /&gt;my $y = pop(@stack);&lt;br /&gt;push(@stack, $x + $y);&lt;br /&gt;next;&lt;br /&gt;}&lt;br /&gt;if ($in eq "/") {&lt;br /&gt;my $x = pop(@stack);&lt;br /&gt;my $y = pop(@stack);&lt;br /&gt;push(@stack, $y / $x);&lt;br /&gt;next;&lt;br /&gt;}&lt;br /&gt;if ($in eq "-") {&lt;br /&gt;my $x = pop(@stack);&lt;br /&gt;my $y = pop(@stack);&lt;br /&gt;push(@stack, $y - $x);&lt;br /&gt;next;&lt;br /&gt;}&lt;br /&gt;if ($in eq "=") {&lt;br /&gt;print pop(@stack), "\n";&lt;br /&gt;next;&lt;br /&gt;}&lt;br /&gt;push @stack, $in;&lt;br /&gt;}&lt;br /&gt; 46&lt;br /&gt;Chapter 8. Advanced Arrays&lt;br /&gt;8.9. shift, unshift&lt;br /&gt;shift and unshift are working on the beginning (left side) of the array.&lt;br /&gt;shift fetches the first element of an array.&lt;br /&gt;It returns the fetched element and the whole array becomes one shorter and moved&lt;br /&gt;to the left. Returns undef if the array was empty.&lt;br /&gt;unshift adds element(s) to the beginning of an array&lt;br /&gt;returns number of elements in the array after the addition&lt;br /&gt;Example:&lt;br /&gt;Example 8-6. examples/arrays/shift_unshift.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my @names = ("Foo", "Bar", "Baz");&lt;br /&gt;my $first = shift @names;&lt;br /&gt;print "$first\n"; # Foo&lt;br /&gt;print "@names\n"; # Bar Baz&lt;br /&gt;unshift @names, "Moo";&lt;br /&gt;print "@names\n"; # Moo Bar Baz&lt;br /&gt;FIRST = shift ARRAY;&lt;br /&gt;unshift ARRAY, VALUEs;&lt;br /&gt;8.10. queue (shift, push)&lt;br /&gt;Example 8-7. examples/arrays/queue.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my @people = ("Foo", "Bar");&lt;br /&gt;while (@people) {&lt;br /&gt;my $next_person = shift @people;&lt;br /&gt;print "$next_person\n"; # do something with this person&lt;br /&gt;print "Type in more people:";&lt;br /&gt;while (my $new = &lt;STDIN&gt;) {&lt;br /&gt; 47&lt;br /&gt;Chapter 8. Advanced Arrays&lt;br /&gt;chomp $new;&lt;br /&gt;push @people, $new;&lt;br /&gt;}&lt;br /&gt;print "\n";&lt;br /&gt;}&lt;br /&gt;8.11. shift&lt;br /&gt;Example 8-8. examples/arrays/shift_argv.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my $filename = shift or die "Usage: $0 FILENAME\n";&lt;br /&gt;shift defaults to shift @ARGV&lt;br /&gt;Another usage of the short circuit&lt;br /&gt;Slight bug (what of the first argument is 0 or the empty string ?&lt;br /&gt;Does it matter?&lt;br /&gt;8.12. sort, reverse&lt;br /&gt;my @reverses_names = reverse @names;&lt;br /&gt;my @sorted_names = sort @names;&lt;br /&gt;8.13. Advanced sort&lt;br /&gt;Example 8-9. examples/arrays/sort.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my @data = (11, 23, 12);&lt;br /&gt;my @sorted = sort @data;&lt;br /&gt;my @sorted_ascii = sort {$a cmp $b} @data;&lt;br /&gt;my @sorted_numeric = sort {$a &lt;=&gt; $b} @data;&lt;br /&gt; 48&lt;br /&gt;Chapter 8. Advanced Arrays&lt;br /&gt;my @sorted_by_length&lt;br /&gt;= sort {length($a) &lt;=&gt; length($b)} @data;&lt;br /&gt;my @sorted_by_length_and_ascii&lt;br /&gt;= sort {&lt;br /&gt;length($a) &lt;=&gt; length($b)&lt;br /&gt;or&lt;br /&gt;$a cmp $b&lt;br /&gt;} @data;&lt;br /&gt;my @sorted_by_abc = sort {lc($a) cmp lc($b)} @data;&lt;br /&gt;my @sorted_abc_ascii&lt;br /&gt;= sort {&lt;br /&gt;lc($a) cmp lc($b)&lt;br /&gt;or&lt;br /&gt;$a cmp $b&lt;br /&gt;} @data;&lt;br /&gt;8.14. Ternary operator&lt;br /&gt;my $var;&lt;br /&gt;if (T) {&lt;br /&gt;$var = A;&lt;br /&gt;} else {&lt;br /&gt;$var = B;&lt;br /&gt;}&lt;br /&gt;my $var = T ? A : B;&lt;br /&gt;8.15. Count digits&lt;br /&gt;Example 8-10. examples/arrays/count_digits.txt&lt;br /&gt;23 34 9512341&lt;br /&gt;3 34 2452345 5353 67 22&lt;br /&gt;42136357013412&lt;br /&gt;42 5 65 64&lt;br /&gt;Example 8-11. examples/arrays/count_digits.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt; 49&lt;br /&gt;Chapter 8. Advanced Arrays&lt;br /&gt;my $filename = shift or die "Usage: $0 filename\n";&lt;br /&gt;my @count;&lt;br /&gt;open(my $fh, "&lt;", $filename)&lt;br /&gt;or die "Could not open ’$filename’: $!";&lt;br /&gt;while (my $line = &lt;$fh&gt;) {&lt;br /&gt;chomp $line;&lt;br /&gt;my @chars = split "", $line;&lt;br /&gt;foreach my $c (@chars) {&lt;br /&gt;if ($c ne " ") {&lt;br /&gt;$count[$c]++;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;foreach my $i (0..9) {&lt;br /&gt;print "$i ", ($count[$i] ? $count[$i] : 0), "\n";&lt;br /&gt;}&lt;br /&gt;8.16. $_&lt;br /&gt;Default variable&lt;br /&gt;foreach my $name (@people) {&lt;br /&gt;print $name;&lt;br /&gt;}&lt;br /&gt;foreach (@people) {&lt;br /&gt;print;&lt;br /&gt;}&lt;br /&gt;foreach $_ (@people) {&lt;br /&gt;print $_;&lt;br /&gt;}&lt;br /&gt;8.17. Diamond operator&lt;br /&gt;Example 8-12. examples/arrays/diamond.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;while (my $line = &lt;&gt;) {&lt;br /&gt;print $line;&lt;br /&gt; 50&lt;br /&gt;Chapter 8. Advanced Arrays&lt;br /&gt;}&lt;br /&gt;8.18. Exercise: median and standard deviation&lt;br /&gt;Now compute the median and the standard deviation of the numbers given in the earlier example.&lt;br /&gt;Median:&lt;br /&gt;if there are odd number of values then - after sorting them - pick the one in the middle.&lt;br /&gt;if there are even number of values, took the 2 in the middle and compute their average&lt;br /&gt;Standard deviation:&lt;br /&gt;sum (for each i) (Xi-average) * (Xi-average)&lt;br /&gt;divide by n (the number of elements)&lt;br /&gt;take the square root of the result&lt;br /&gt;8.19. Exercise: sort mixed string&lt;br /&gt;In a file we have the following strings: A1 A27 A38 B1 ...&lt;br /&gt;each string has a letter at the beginning and then a number.&lt;br /&gt;Sort them first based on the first letter and among values with the same&lt;br /&gt;leading letter sort them according to the numbers.&lt;br /&gt;File:&lt;br /&gt;Example 8-13. examples/arrays/sort_mixed_strings.txt&lt;br /&gt;A1&lt;br /&gt;A27&lt;br /&gt;C1&lt;br /&gt;B1&lt;br /&gt;B12&lt;br /&gt;A38&lt;br /&gt;B3&lt;br /&gt;A3&lt;br /&gt;8.20. Solution: median and standard deviation&lt;br /&gt;Example 8-14. examples/arrays/statistics_more.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt; 51&lt;br /&gt;Chapter 8. Advanced Arrays&lt;br /&gt;my @data = &lt;STDIN&gt;;&lt;br /&gt;chomp @data;&lt;br /&gt;@data = sort { $a &lt;=&gt; $b } @data;&lt;br /&gt;if (not @data) {&lt;br /&gt;print "No values were given\n";&lt;br /&gt;exit;&lt;br /&gt;}&lt;br /&gt;my $total = 0;&lt;br /&gt;foreach my $v (@data) {&lt;br /&gt;$total += $v;&lt;br /&gt;}&lt;br /&gt;my $average = $total / @data;&lt;br /&gt;my $median = @data % 2 ? $data[(@data-1)/2]&lt;br /&gt;: ($data[@data/2-1]+$data[@data/2])/2&lt;br /&gt;;&lt;br /&gt;my $sqtotal = 0;&lt;br /&gt;foreach my $v (@data) {&lt;br /&gt;$sqtotal += ($average-$v) ** 2;&lt;br /&gt;}&lt;br /&gt;my $std = ($sqtotal / @data) ** 0.5;&lt;br /&gt;print "Min: $data[0] Max: $data[-1] Total: $total count: "&lt;br /&gt;. @data . " Average: $average\n";&lt;br /&gt;print "Median: $median $sqtotal Standard deviation: $std\n";&lt;br /&gt;8.21. Solution: sort mixed strings&lt;br /&gt;Example 8-15. examples/arrays/sort_mixed_strings.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my $file = ’sort_mixed_strings.txt’;&lt;br /&gt;if (@ARGV) {&lt;br /&gt;$file = shift;&lt;br /&gt;}&lt;br /&gt;open(my $fh, ’&lt;’, $file) or die "Could not open ’$file’\n";&lt;br /&gt;my @data = &lt;$fh&gt;;&lt;br /&gt;chomp @data;&lt;br /&gt; 52&lt;br /&gt;Chapter 8. Advanced Arrays&lt;br /&gt;my @sorted = sort {&lt;br /&gt;substr($a, 0, 1) cmp substr($b, 0, 1)&lt;br /&gt;or&lt;br /&gt;substr($a, 1) &lt;=&gt; substr($b, 1) } @data;&lt;br /&gt;foreach my $v (@sorted) {&lt;br /&gt;print "$v\n";&lt;br /&gt;}&lt;br /&gt;8.22. grep&lt;br /&gt;Example 8-16. examples/arrays/grep_perl.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my @numbers = (1..30);&lt;br /&gt;my @odd_numbers = grep { $_ % 2 } @numbers;&lt;br /&gt;foreach my $num (@odd_numbers) {&lt;br /&gt;print "$num\n";&lt;br /&gt;}&lt;br /&gt;8.23. map&lt;br /&gt;Example 8-17. examples/arrays/map_perl.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my @numbers = (1..30);&lt;br /&gt;my @doubles = map {$_ * 2} @numbers;&lt;br /&gt;foreach my $num (@doubles) {&lt;br /&gt;print "$num\n";&lt;br /&gt;}&lt;br /&gt;8.24. List::Util&lt;br /&gt;List::Util provides functions such as&lt;br /&gt;• max&lt;br /&gt; 53&lt;br /&gt;Chapter 8. Advanced Arrays&lt;br /&gt;• min&lt;br /&gt;• sum&lt;br /&gt;It resides in a distribution called Scalar::List::Utils http://search.cpan.org/dist/Scalar-List-Utils&lt;br /&gt;8.25. Advanced: Multi dimensional array&lt;br /&gt;Example 8-18. examples/arrays/matrix.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my @matrix;&lt;br /&gt;$matrix[0][0] = 0;&lt;br /&gt;$matrix[1][1] = 11;&lt;br /&gt;$matrix[1][2] = 12;&lt;br /&gt;#print "$matrix\n";&lt;br /&gt;print "$matrix[0]\n"; # ARRAY(0x814dd90)&lt;br /&gt;print "$matrix[1][1]\n"; # 11&lt;br /&gt;use Data::Dumper qw(Dumper);&lt;br /&gt;print Dumper \@matrix;&lt;br /&gt;Actually what we have is a simple array and each element of that&lt;br /&gt;array can be another (anonymous) array (reference).&lt;br /&gt;8.26. splice&lt;br /&gt;Removes the elements designated by OFFSET and LENGTH (and returns them).&lt;br /&gt;Replaces them with the content of the 4th parameter.&lt;br /&gt;Example 8-19. examples/arrays/splice.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my @names = qw(Foo Bar Baz Moo Qux Barney Hoppy Bammbamm Dino);&lt;br /&gt;my @more_names = qw(Fred Wilma);&lt;br /&gt; 54&lt;br /&gt;Chapter 8. Advanced Arrays&lt;br /&gt;my @sublist = splice(@names, 2, 3);&lt;br /&gt;print "@sublist\n"; # Baz Moo Qux&lt;br /&gt;print "@names\n"; # Foo Bar Barney Hoppy Bammbamm Dino&lt;br /&gt;my @zlist = splice(@names, 2, 3, @more_names);&lt;br /&gt;print "@zlist\n"; # Barney Hoppy Bammbamm&lt;br /&gt;print "@names\n"; # Foo Bar Fred Wilma Dino&lt;br /&gt; 55&lt;br /&gt;Chapter 9. Functions and Subroutines&lt;br /&gt;9.1. Subroutines&lt;br /&gt;Example 9-1. examples/subroutines/subroutines.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my $sum = add(2, 3);&lt;br /&gt;print "$sum\n";&lt;br /&gt;print add(5, 8), "\n";&lt;br /&gt;my $result = add2(4, 7);&lt;br /&gt;print "$result\n";&lt;br /&gt;print sum(3, 7, 11, 21), "\n";&lt;br /&gt;sub add {&lt;br /&gt;my ($x, $y) = @_;&lt;br /&gt;my $z = $x+$y;&lt;br /&gt;return $z;&lt;br /&gt;}&lt;br /&gt;sub add2 {&lt;br /&gt;my $x = shift;&lt;br /&gt;my $y = shift;&lt;br /&gt;return $x+$y;&lt;br /&gt;}&lt;br /&gt;sub add_ugly {&lt;br /&gt;return $_[0]+$_[1];&lt;br /&gt;}&lt;br /&gt;sub sum {&lt;br /&gt;my $sum = 0;&lt;br /&gt;foreach my $v (@_) {&lt;br /&gt;$sum += $v;&lt;br /&gt;}&lt;br /&gt;return $sum;&lt;br /&gt;}&lt;br /&gt;56&lt;br /&gt;Chapter 9. Functions and Subroutines&lt;br /&gt;9.2. Recoursive subroutines&lt;br /&gt;Example 9-2. examples/subroutines/factorial.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my $n = shift or die "Usage: $0 NUMBER\n";&lt;br /&gt;my $result = factorial($n);&lt;br /&gt;print $result;&lt;br /&gt;sub factorial {&lt;br /&gt;my ($n) = @_;&lt;br /&gt;if ($n == 1) {&lt;br /&gt;return 1;&lt;br /&gt;}&lt;br /&gt;my $prev = factorial($n - 1);&lt;br /&gt;return $n * $prev;&lt;br /&gt;}&lt;br /&gt;Example 9-3. examples/subroutines/fibonacci_recoursive.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;sub fib {&lt;br /&gt;my $n = shift;&lt;br /&gt;if ($n == 0 or $n == 1) {&lt;br /&gt;return 1&lt;br /&gt;}&lt;br /&gt;return (fib($n-1)+fib($n-2)); # recursive calling&lt;br /&gt;}&lt;br /&gt;print fib(10); # calling the function&lt;br /&gt;9.3. Sort using a function&lt;br /&gt;Example 9-4. examples/subroutines/sort_with_function.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my @data = (23, 1, 12, 3, 48);&lt;br /&gt; 57&lt;br /&gt;Chapter 9. Functions and Subroutines&lt;br /&gt;my @sorted = sort by_number @data;&lt;br /&gt;print "@data\n";&lt;br /&gt;print "@sorted\n";&lt;br /&gt;sub by_number {&lt;br /&gt;return $a &lt;=&gt; $b;&lt;br /&gt;}&lt;br /&gt;9.4. Return a list&lt;br /&gt;Perl allows us to return any number of values.&lt;br /&gt;Example 9-5. examples/subroutines/fibonacci.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my @numbers = fib(10);&lt;br /&gt;print "@numbers\n";&lt;br /&gt;sub fib {&lt;br /&gt;my $num = shift;&lt;br /&gt;my @fib;&lt;br /&gt;if ($num == 1) {&lt;br /&gt;return (1);&lt;br /&gt;}&lt;br /&gt;if ($num == 2) {&lt;br /&gt;return (1, 1);&lt;br /&gt;}&lt;br /&gt;@fib = (1, 1);&lt;br /&gt;foreach (3..$num) {&lt;br /&gt;push @fib, $fib[-1]+$fib[-2];&lt;br /&gt;}&lt;br /&gt;return @fib;&lt;br /&gt;}&lt;br /&gt;9.5. Error handling with eval&lt;br /&gt;Example 9-6. examples/subroutines/eval.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt; 58&lt;br /&gt;Chapter 9. Functions and Subroutines&lt;br /&gt;my $result;&lt;br /&gt;my $x = 19;&lt;br /&gt;my $y = 23;&lt;br /&gt;eval {&lt;br /&gt;$result = unstable_add_function($x, $y);&lt;br /&gt;print "unstable done\n";&lt;br /&gt;};&lt;br /&gt;if ($@) {&lt;br /&gt;chomp $@;&lt;br /&gt;warn "Exception ’$@’ received\n";&lt;br /&gt;$result = slow_but_stable_add($x, $y);&lt;br /&gt;print "slow done\n";&lt;br /&gt;}&lt;br /&gt;print "Result: $result\n";&lt;br /&gt;sub unstable_add_function {&lt;br /&gt;if (rand() &lt; 0.2) {&lt;br /&gt;die "broken";&lt;br /&gt;}&lt;br /&gt;return $_[0]+$_[1];&lt;br /&gt;}&lt;br /&gt;sub slow_but_stable_add {&lt;br /&gt;sleep (2);&lt;br /&gt;return $_[0]+$_[1];&lt;br /&gt;}&lt;br /&gt; 59&lt;br /&gt;Chapter 10. Associative Arrays (Hashes)&lt;br /&gt;10.1. What is a hash?&lt;br /&gt;• Unordered group of key/value pairs where&lt;br /&gt;• key is a unique string&lt;br /&gt;• value is any scalar&lt;br /&gt;10.2. Uses of hashes&lt;br /&gt;Mapping of single feature of many similar items:&lt;br /&gt;• phone book (name =&gt; phone number)&lt;br /&gt;• worker list (ID number =&gt; name)&lt;br /&gt;• CGI: (fieldname =&gt; field value)&lt;br /&gt;Features of an object:&lt;br /&gt;• Information about a person (fname, lname, email, phone, ...)&lt;br /&gt;10.3. Creating hashes&lt;br /&gt;my %user;&lt;br /&gt;%user = ("fname", "Foo", "lname", "Bar");&lt;br /&gt;my %user = (&lt;br /&gt;"fname", "Foo",&lt;br /&gt;"lname", "Bar",&lt;br /&gt;);&lt;br /&gt;my %user = (&lt;br /&gt;fname =&gt; "Foo",&lt;br /&gt;lname =&gt; "Bar",&lt;br /&gt;);&lt;br /&gt;print $user{fname}, "\n";&lt;br /&gt;$user{fname} = ’Moo’;&lt;br /&gt;$user{email} = ’foo@bar.com’;&lt;br /&gt;60&lt;br /&gt;Chapter 10. Associative Arrays (Hashes)&lt;br /&gt;10.4. Create hash from an array&lt;br /&gt;my @person = qw(fname Foo lname Bar);&lt;br /&gt;my %user = @person;&lt;br /&gt;my @foobar = %user;&lt;br /&gt;print "@foobar\n"; # fname Foo lname Bar&lt;br /&gt;$user{phone} = ’123-456’;&lt;br /&gt;%user = (phone =&gt; ’123-456’); # removes all previous elements from the hash&lt;br /&gt;10.5. Hash in scalar context&lt;br /&gt;Previously we saw that a hash in LIST context returns its keys and values.&lt;br /&gt;In SCALAR context:&lt;br /&gt;if (%h) {&lt;br /&gt;# the hash is not empty&lt;br /&gt;}&lt;br /&gt;10.6. Fetching data from hash&lt;br /&gt;my @fields = keys %user;&lt;br /&gt;foreach my $field (@fields) {&lt;br /&gt;print "$field $user{$field}\n";&lt;br /&gt;}&lt;br /&gt;foreach my $field (keys %user) {&lt;br /&gt;print "$field $user{$field}\n";&lt;br /&gt;}&lt;br /&gt;my @fields = keys %user;&lt;br /&gt;my @sorted_fields = sort @fields;&lt;br /&gt;foreach my $field (@sorted_fields) {&lt;br /&gt;print "$field $user{$field}\n";&lt;br /&gt;}&lt;br /&gt;foreach my $field (sort keys %user) {&lt;br /&gt;print "$field $user{$field}\n";&lt;br /&gt;}&lt;br /&gt; 61&lt;br /&gt;Chapter 10. Associative Arrays (Hashes)&lt;br /&gt;10.7. exists, delete hash element&lt;br /&gt;my %phones;&lt;br /&gt;$phones{Foo} = ’111’;&lt;br /&gt;$phones{Bar} = ’222’;&lt;br /&gt;$phones{Moo} = undef;&lt;br /&gt;if (exists $phones{Foo}) {&lt;br /&gt;if (defined $phones{Foo}) {&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;delete $phones{Foo};&lt;br /&gt;10.8. Multi dimensional hashes&lt;br /&gt;Example 10-1. examples/hashes/grades.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my %grades;&lt;br /&gt;$grades{"Foo Bar"}{Mathematics} = 97;&lt;br /&gt;$grades{"Foo Bar"}{Literature} = 67;&lt;br /&gt;$grades{"Peti Bar"}{Literature} = 88;&lt;br /&gt;$grades{"Peti Bar"}{Mathematics} = 82;&lt;br /&gt;$grades{"Peti Bar"}{Art} = 99;&lt;br /&gt;foreach my $name (sort keys %grades) {&lt;br /&gt;foreach my $subject (keys %{$grades{$name}}) {&lt;br /&gt;print "$name, $subject: $grades{$name}{$subject}\n";&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;10.9. Dumping hashes&lt;br /&gt;use Data::Dumper qw(Dumper);&lt;br /&gt;print Dumper \%grades;&lt;br /&gt;$VAR1 = {&lt;br /&gt;’Peti Bar’ =&gt; {&lt;br /&gt;’Art’ =&gt; 99,&lt;br /&gt;’Literature’ =&gt; 88,&lt;br /&gt;’Mathematics’ =&gt; 82&lt;br /&gt;},&lt;br /&gt; 62&lt;br /&gt;Chapter 10. Associative Arrays (Hashes)&lt;br /&gt;’Foo Bar’ =&gt; {&lt;br /&gt;’Literature’ =&gt; 67,&lt;br /&gt;’Mathematics’ =&gt; 97&lt;br /&gt;}&lt;br /&gt;};&lt;br /&gt;10.10. Count words&lt;br /&gt;• %hash, $hash{element}&lt;br /&gt;• keys&lt;br /&gt;Example 10-2. examples/hashes/count_words_hash.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my $filename = shift or die "Usage: $0 filename\n";&lt;br /&gt;my %count;&lt;br /&gt;open(my $fh, "&lt;", $filename)&lt;br /&gt;or die "Could not open ’$filename’: $!";&lt;br /&gt;while (my $line = &lt;$fh&gt;) {&lt;br /&gt;chomp $line;&lt;br /&gt;my @words = split " ", $line;&lt;br /&gt;foreach my $word (@words) {&lt;br /&gt;$count{$word}++;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;foreach my $word (keys %count) {&lt;br /&gt;print "$word : $count{$word}\n";&lt;br /&gt;}&lt;br /&gt;10.11. Exercise: Parse HTTP values&lt;br /&gt;You get one line like the following:&lt;br /&gt;fname=Foo&amp;lname=Bar&amp;phone=123&amp;email=foo@bar.com&lt;br /&gt;Build a hash table from it so:&lt;br /&gt;print $h{fname}; # Foo&lt;br /&gt;print $h{lname}; # Bar&lt;br /&gt;...&lt;br /&gt; 63&lt;br /&gt;Chapter 10. Associative Arrays (Hashes)&lt;br /&gt;10.12. Exercise: Improve the color selector&lt;br /&gt;In the external file where we defined the colors, for each color&lt;br /&gt;keep also a character that will be used to display the menu:&lt;br /&gt;File:&lt;br /&gt;yellow y&lt;br /&gt;brown z&lt;br /&gt;black b&lt;br /&gt;blue e&lt;br /&gt;When displaying the menu show:&lt;br /&gt;y) yellow&lt;br /&gt;z) brown&lt;br /&gt;b) black&lt;br /&gt;e) blue&lt;br /&gt;and wait till the user selects the appropriate letter.&lt;br /&gt;10.13. Exercise: Display scores&lt;br /&gt;Read in a file where on each line there is a name and a score&lt;br /&gt;with a comma between them.&lt;br /&gt;Print them sorted based on name.&lt;br /&gt;Then also print sorted based on score.&lt;br /&gt;Example 10-3. examples/hashes/score_data.txt&lt;br /&gt;Foo,23&lt;br /&gt;Bar,70&lt;br /&gt;Baz,92&lt;br /&gt;Bozo,17&lt;br /&gt;Gozo,52&lt;br /&gt;Dardon,20&lt;br /&gt;Mekodra,23&lt;br /&gt;10.14. Exercise: Analyze Apache log file&lt;br /&gt;In the files section earlier we had a an example counting&lt;br /&gt;how many hist came from localhost and from other places.&lt;br /&gt;Please improve that analyzer to provide a report:&lt;br /&gt;which client IP addresse were used and how many hits were from&lt;br /&gt; 64&lt;br /&gt;Chapter 10. Associative Arrays (Hashes)&lt;br /&gt;each IP adddress.&lt;br /&gt;The log file can be found here:&lt;br /&gt;examples/files/apache_access.log&lt;br /&gt;10.15. Exercise: Parse variable width fields&lt;br /&gt;Example 10-4. examples/hashes/variable_width_fields.log&lt;br /&gt;# In a log file there are rows in which the first 16 and last 16 characters&lt;br /&gt;# describe addresses while everything in between describes several commands&lt;br /&gt;# Each command is built up by a leading character (A, B, C, D, etc) and a number&lt;br /&gt;# of digits. The number of digits depend on the leading character.&lt;br /&gt;#&lt;br /&gt;# In this example we split up the data to commands and count how many times&lt;br /&gt;# each command type was given.&lt;br /&gt;#&lt;br /&gt;1234567890123456A001B0002D00004C0000051234567890123456&lt;br /&gt;1234567890123456A001A002D00004C0000051234567890123456&lt;br /&gt;10.16. Solution: Parse HTTP values&lt;br /&gt;Example 10-5. examples/hashes/split_http.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my $str = ’fname=Foo&amp;lname=Bar&amp;email=foo@bar.com’;&lt;br /&gt;my @pairs = split "&amp;", $str;&lt;br /&gt;my %data;&lt;br /&gt;foreach my $p (@pairs) {&lt;br /&gt;my ($k, $v) = split "=", $p;&lt;br /&gt;$data{$k} = $v;&lt;br /&gt;}&lt;br /&gt;use Data::Dumper;&lt;br /&gt;print Dumper \%data;&lt;br /&gt; 65&lt;br /&gt;Chapter 10. Associative Arrays (Hashes)&lt;br /&gt;10.17. Solution: Improve the color selector&lt;br /&gt;Example 10-6. examples/hashes/color_selector_file.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;use Getopt::Long qw(GetOptions);&lt;br /&gt;my $color;&lt;br /&gt;my $filename = "examples/color_map.txt";&lt;br /&gt;my $force;&lt;br /&gt;GetOptions(&lt;br /&gt;"color=s" =&gt; \$color,&lt;br /&gt;"filename=s" =&gt; \$filename,&lt;br /&gt;"force" =&gt; \$force,&lt;br /&gt;);&lt;br /&gt;my %colors;&lt;br /&gt;open(my $fh, "&lt;", $filename)&lt;br /&gt;or die "Could not open ’$filename’ for reading: $!";&lt;br /&gt;while (my $line = &lt;$fh&gt;) {&lt;br /&gt;chomp $line;&lt;br /&gt;my ($color_name, $letter) = split " ", $line;&lt;br /&gt;if ($colors{$letter}) {&lt;br /&gt;warn&lt;br /&gt;sprintf "%s appears to be allocated to both %s and %s\n",&lt;br /&gt;$letter, $colors{$letter}, $color_name&lt;br /&gt;} else {&lt;br /&gt;$colors{$letter} = $color_name;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;if ($color and not $force) {&lt;br /&gt;my $valid_color;&lt;br /&gt;foreach my $c (values %colors) {&lt;br /&gt;if ($c eq $color) {&lt;br /&gt;$valid_color = 1;&lt;br /&gt;next;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;if (not $valid_color) {&lt;br /&gt;print "The color ’$color’ is not valid.\n";&lt;br /&gt;$color = ”;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;if (not $color) {&lt;br /&gt;print "Please select a number:\n";&lt;br /&gt; 66&lt;br /&gt;Chapter 10. Associative Arrays (Hashes)&lt;br /&gt;foreach my $k (sort keys %colors) {&lt;br /&gt;print "$k) $colors{$k}\n";&lt;br /&gt;}&lt;br /&gt;my $letter = &lt;STDIN&gt;;&lt;br /&gt;chomp($letter);&lt;br /&gt;if ($colors{$letter}) {&lt;br /&gt;$color = $colors{$letter};&lt;br /&gt;} else {&lt;br /&gt;print "Bad selection\n";&lt;br /&gt;exit;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;print "The selected color is $color\n";&lt;br /&gt;10.18. Solution: Display scores&lt;br /&gt;Example 10-7. examples/hashes/score_data.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my $filename = shift or die "Usage: $0 FILENAME\n";&lt;br /&gt;open(my $fh, "&lt;", $filename) or die "Could not open ’$filename’\n";&lt;br /&gt;my %score_of;&lt;br /&gt;while (my $line = &lt;$fh&gt;) {&lt;br /&gt;chomp $line;&lt;br /&gt;my ($name, $score) = split ",", $line;&lt;br /&gt;$score_of{$name} = $score;&lt;br /&gt;}&lt;br /&gt;foreach my $name (sort keys %score_of) {&lt;br /&gt;printf "%-10s %s\n", $name, $score_of{$name};&lt;br /&gt;}&lt;br /&gt;print "--------------------------\n";&lt;br /&gt;foreach my $name (sort {&lt;br /&gt;$score_of{$b} &lt;=&gt; $score_of{$a}&lt;br /&gt;} keys %score_of) {&lt;br /&gt;printf "%-10s %s\n", $name, $score_of{$name};&lt;br /&gt;}&lt;br /&gt; 67&lt;br /&gt;Chapter 10. Associative Arrays (Hashes)&lt;br /&gt;10.19. Solution: Analyze Apache log file&lt;br /&gt;Example 10-8. examples/hashes/apache_log_hosts_hash.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my $file = shift or die "Usage: $0 FILENAME (examples/files/apache_access.log)\n";&lt;br /&gt;open my $fh, ’&lt;’, $file or die $!;&lt;br /&gt;my %count;&lt;br /&gt;while (my $line = &lt;$fh&gt;) {&lt;br /&gt;chomp $line;&lt;br /&gt;my $length = index ($line, " ");&lt;br /&gt;my $ip = substr($line, 0, $length);&lt;br /&gt;$count{$ip}++;&lt;br /&gt;}&lt;br /&gt;foreach my $ip (keys %count) {&lt;br /&gt;print "$ip $count{$ip}\n";&lt;br /&gt;}&lt;br /&gt;10.20. Solution: Parse variable width fields&lt;br /&gt;Example 10-9. examples/hashes/parse_variable_width_fields.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my %count;&lt;br /&gt;my %length = (&lt;br /&gt;A =&gt; 3,&lt;br /&gt;B =&gt; 4,&lt;br /&gt;C =&gt; 6,&lt;br /&gt;D =&gt; 5,&lt;br /&gt;);&lt;br /&gt;my $filename = "examples/hashes/variable_width_fields.log";&lt;br /&gt;if ($ARGV[0]) {&lt;br /&gt;$filename = $ARGV[0];&lt;br /&gt;}&lt;br /&gt;open my $data, ’&lt;’, $filename or die "Could not open ’$filename’ $!";&lt;br /&gt;LINE:&lt;br /&gt;while (my $line = &lt;$data&gt;) {&lt;br /&gt;chomp $line;&lt;br /&gt; 68&lt;br /&gt;Chapter 10. Associative Arrays (Hashes)&lt;br /&gt;if (substr($line, 0, 1) eq "#") {&lt;br /&gt;next;&lt;br /&gt;}&lt;br /&gt;#print $line;&lt;br /&gt;my $cmds = substr($line, 16, -16);&lt;br /&gt;#print $cmds;&lt;br /&gt;while ($cmds) {&lt;br /&gt;my $c = substr($cmds,0,1, "");&lt;br /&gt;#print "$c\n";&lt;br /&gt;#print "$cmds\n";&lt;br /&gt;if (not defined $length{$c}) {&lt;br /&gt;warn "....";&lt;br /&gt;next LINE;&lt;br /&gt;}&lt;br /&gt;my $cmd = substr($cmds,0, $length{$c}, "");&lt;br /&gt;$count{$c}++;&lt;br /&gt;print "$c : $cmd\n";&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;print "-" x 80, "\n";&lt;br /&gt;foreach my $c (keys %count) {&lt;br /&gt;print "$c $count{$c}\n";&lt;br /&gt;}&lt;br /&gt; 69&lt;br /&gt;Chapter 11. Regular Expressions&lt;br /&gt;11.1. What are regexes good for ?&lt;br /&gt;• Decide if a string is part of a larger string&lt;br /&gt;• Validate the format of some value (string) (e.g. is it a decimal number?, is it a hex?)&lt;br /&gt;• Find if there are repetitions in a string&lt;br /&gt;• Analyse a string and fetch parts of if given some loose description&lt;br /&gt;11.2. Examples&lt;br /&gt;Which one is a number: 23, 2.3 2.3.4 2.4e3 abc ?&lt;br /&gt;Is there a word in the file that is repeated 3 or more times?&lt;br /&gt;Replaces all occurances of Perl or perl by Java ...&lt;br /&gt;... but avoid replacing Perla.&lt;br /&gt;11.3. Introduction to Regexes&lt;br /&gt;my $str = "Some string here";&lt;br /&gt;if ($str =~ /ome/) {&lt;br /&gt;print "There is a match\n";&lt;br /&gt;}&lt;br /&gt;if ($str !~ /s r/) {&lt;br /&gt;print "No match\n";&lt;br /&gt;}&lt;br /&gt;11.4. Find a string in a file&lt;br /&gt;Example 11-1. examples/regex/find_string.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my $filename = shift or die "$0 FILENAME\n";&lt;br /&gt;70&lt;br /&gt;Chapter 11. Regular Expressions&lt;br /&gt;open my $fh, ’&lt;’, $filename or die "Could not open ’$filename’\n";&lt;br /&gt;while (my $line = &lt;$fh&gt;) {&lt;br /&gt;if ($line =~ /REGEX/) {&lt;br /&gt;print $line;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;11.5. Tools&lt;br /&gt;Regex Coach: http://weitz.de/regex-coach/&lt;br /&gt;11.6. Regex Examples: single character&lt;br /&gt;Any line that has an ’x’ in it.&lt;br /&gt;Regex: /x/&lt;br /&gt;Input: "abcde"&lt;br /&gt;Input: "abxcde"&lt;br /&gt;Input: "xabcde"&lt;br /&gt;Any line that starts with an ’x’.&lt;br /&gt;Regex: /^x/&lt;br /&gt;Input: "abcde"&lt;br /&gt;Input: "abxcde"&lt;br /&gt;Input: "xabcde"&lt;br /&gt;Input: " xabcde"&lt;br /&gt;^ at the beginning of the regular expression means, match at the beginning of the string.&lt;br /&gt;11.7. Regex Examples dot (.)&lt;br /&gt;Any line that has any of the xax, xbx, ..., that is any character between two x-es.&lt;br /&gt;Regex: /x.x/&lt;br /&gt;Input: "abcde"&lt;br /&gt;Input: "abxcxbde"&lt;br /&gt;Input: "xabcde"&lt;br /&gt;Input: "xabxcxde"&lt;br /&gt;1&lt;br /&gt;Chapter 11. Regular Expressions&lt;br /&gt;Any line that has x.x (A real . between two x-es.)&lt;br /&gt;Regex: /x\.x/&lt;br /&gt;The special characters are: . * + ? ^ $ \ ( ) [ ] | { } and the delimiter: /&lt;br /&gt;Some of the characters change their special meaning based on position.&lt;br /&gt;11.8. Regex Examples (character class)&lt;br /&gt;Any line that has any of the -a-, -b-, -c-, -d-, -e-, -f-, -@- or -.-&lt;br /&gt;Regex: /-[abcdef@.]-/&lt;br /&gt;Input: "ab -q- "&lt;br /&gt;Input: "ab -z-a- "&lt;br /&gt;Input: "ab -.- "&lt;br /&gt;Input: "ab -- "&lt;br /&gt;Regex: /-[a-f@.]-/&lt;br /&gt;11.9. Regex Examples (^ in character class)&lt;br /&gt;^ as the first character in a character class means "a character that is not listed in this character class"&lt;br /&gt;Regex: /-[^abc]-/&lt;br /&gt;Input: "abc -a- z"&lt;br /&gt;Input: "abc -z- z"&lt;br /&gt;11.10. Regex Examples quantifiers&lt;br /&gt;Any line with two - -es with anything in between.&lt;br /&gt;Regex: /-.*-/&lt;br /&gt;Input: "ab"&lt;br /&gt;2&lt;br /&gt;Chapter 11. Regular Expressions&lt;br /&gt;Input: "ab - cde"&lt;br /&gt;Input: "ab - qqqrq -"&lt;br /&gt;Input: "ab -- cde"&lt;br /&gt;Input: "--"&lt;br /&gt;11.11. Quantifiers&lt;br /&gt;Quantifiers apply to the thing in front of them&lt;br /&gt;/ab*a/ # aa, aba, abba, abbba, ...&lt;br /&gt;/ab+a/ # aba, abba, abbba, ...&lt;br /&gt;/ab?a/ # aa, aba&lt;br /&gt;/ab{2,4}a/ # abba, abbba, abbbba&lt;br /&gt;/ab{3,}a/ # abbba, abbbba, ...&lt;br /&gt;/ab{17}a/ # abbbbbbbbbbbbbbbbba&lt;br /&gt;Table 11-1. Quantifiers&lt;br /&gt;* 0-&lt;br /&gt;+ 1-&lt;br /&gt;? 0-1&lt;br /&gt;{n,m} n-m&lt;br /&gt;{n,} n-&lt;br /&gt;{n} n&lt;br /&gt;11.12. Quantifiers on character classes&lt;br /&gt;Regex: /-[abc]-/&lt;br /&gt;Input: "-a-" OK&lt;br /&gt;Input: "-b-" OK&lt;br /&gt;Input: "-x-"&lt;br /&gt;Input: "-ab-"&lt;br /&gt;Regex: /-[abc]+-/&lt;br /&gt;Input: "-a-" OK&lt;br /&gt;Input: "-b-" OK&lt;br /&gt;Input: "-ab-" OK&lt;br /&gt;Input: "-aa-" OK&lt;br /&gt;Input: "-x-"&lt;br /&gt;3&lt;br /&gt;Chapter 11. Regular Expressions&lt;br /&gt;11.13. Exercises: Regular expressions&lt;br /&gt;Pick up a vocabulary. Based on the following template write a script that&lt;br /&gt;prints out every word from the list of words&lt;br /&gt;(see examples/regex/dict.txt ) that&lt;br /&gt;• has an ’a’&lt;br /&gt;• starts with an ’a’&lt;br /&gt;• has ’th’&lt;br /&gt;• has an ’a’ or an ’A’&lt;br /&gt;• has a ’*’ in it&lt;br /&gt;• starts with an ’a’ or an ’A’&lt;br /&gt;• has both ’a’ and ’e’ in it&lt;br /&gt;• has an ’a’ followed by an ’e’ somewhere in it&lt;br /&gt;• does not have an ’a’&lt;br /&gt;• does not have an ’a’ nor ’e’&lt;br /&gt;• has an ’a’ but not ’e’&lt;br /&gt;• has at least 2 consequtive vowels (a,e,i,o,u)&lt;br /&gt;• has at least 3 vowels&lt;br /&gt;• has at least 6 characters&lt;br /&gt;• has at exactly 6 characters&lt;br /&gt;• Bonus: all the words with either ’aba’ or ’ada’ in them&lt;br /&gt;• Bonus: all the words with either ’aba’ or ’eda’ in them&lt;br /&gt;• Bonus: has a double character (e.g. ’oo’)&lt;br /&gt;• Bonus: for every word print the first vowel&lt;br /&gt;Example 11-2. examples/regex/regex_exercise.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my $filename = shift or die "$0 FILENAME\n";&lt;br /&gt;open my $fh, ’&lt;’, $filename or die "Could not open ’$filename’\n";&lt;br /&gt;while (my $line = &lt;$fh&gt;) {&lt;br /&gt;if ($line =~ /REGEX1/) {&lt;br /&gt;print "has an a: $line";&lt;br /&gt;}&lt;br /&gt;if ($line =~ /REGEX2/) {&lt;br /&gt;4&lt;br /&gt;Chapter 11. Regular Expressions&lt;br /&gt;print "starts with an a: $line";&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;11.14. Solutions: Regular expressions&lt;br /&gt;• /a/&lt;br /&gt;• /^a/&lt;br /&gt;• /th/&lt;br /&gt;• /[aA]/&lt;br /&gt;• /\*/&lt;br /&gt;• another solution: /[*]/&lt;br /&gt;• /^[aA]/&lt;br /&gt;• $str =~ /a/ and $str =~ /e/&lt;br /&gt;• /a.*e/&lt;br /&gt;• $str !~ /a/&lt;br /&gt;• $str !~ /[ae]/&lt;br /&gt;• $str =~ /a/ and $str !~ /e/&lt;br /&gt;• /[aeiou]{2}/&lt;br /&gt;• /[aeiou].*[aeiou].*[aeiou]/&lt;br /&gt;• /....../ /.{6}/&lt;br /&gt;• length($str) == 6&lt;br /&gt;11.15. Grouping, alternatives&lt;br /&gt;Bonus: all the words with either ’aba’ or ’ada’ in them&lt;br /&gt;Bonus: all the words with either ’aba’ or ’eda’ in them&lt;br /&gt;/a[bd]a/&lt;br /&gt;if ($line =~ /aba/ or $line =~ /eda/) {&lt;br /&gt;}&lt;br /&gt;if ($line =~ /aba|eda/) {&lt;br /&gt;}&lt;br /&gt;if ($line =~ /(ab|ed)a/) {&lt;br /&gt;}&lt;br /&gt;5&lt;br /&gt;Chapter 11. Regular Expressions&lt;br /&gt;11.16. Capturing&lt;br /&gt;Bounus: for every word print the first vowel&lt;br /&gt;if ($line =~ /([aeiou])/) {&lt;br /&gt;print $1;&lt;br /&gt;}&lt;br /&gt;Bonus: has a double character (e.g. ’oo’)&lt;br /&gt;Input: "my loop"&lt;br /&gt;/.o/&lt;br /&gt;/(.)o/&lt;br /&gt;if ($line =~ /(.)\1/) {&lt;br /&gt;print $1;&lt;br /&gt;}&lt;br /&gt;/(.+).*\1/ # lines with anything more than once&lt;br /&gt;/((.+).*\1)+/ # Syntax error ! Why ?&lt;br /&gt;if ($line =~ /(.*)=(.*)/) {&lt;br /&gt;print "left: $1\n";&lt;br /&gt;print "right: $2\n";&lt;br /&gt;}&lt;br /&gt;11.17. Anchors&lt;br /&gt;^ # at the beginning of the pattern means beginning of the string&lt;br /&gt;$ # at the end of the pattern means the end of the string&lt;br /&gt;/the/ # matches anywhere in the string: "atheneum", "thermostat", "the", /^the/ # matches only if the string starts with the "thermostat", "the"&lt;br /&gt;/the$/ # matches only if the string ends with the "the", "mathe"&lt;br /&gt;/^the$/ # matches only if the string "the"&lt;br /&gt;/^\s*$/ # the string contains only white spaces (it looks like an empty string)&lt;br /&gt;\b # Word delimiter&lt;br /&gt;/\bstruct\b/ # match every place the word "struct" but not "structure" or "construct"&lt;br /&gt;/\b\w+\b/ # A single "word"&lt;br /&gt;11.18. Character classes&lt;br /&gt;A list of optional characters within square brackets []&lt;br /&gt;6&lt;br /&gt;Chapter 11. Regular Expressions&lt;br /&gt;/a[bc]a/ # aba, aca&lt;br /&gt;/a[2#=x?.]a/ # a2a, a#a, a=a, axa, a?a, a.a&lt;br /&gt;# inside the character class most of the spec characters lose their&lt;br /&gt;# special meaning BUT there are some new special characters&lt;br /&gt;/a[2-8]a/ # is the same as /a[2345678]a/&lt;br /&gt;/a[2-]a/ # a2a, a-a - has no special meaning at the ends&lt;br /&gt;/a[-8]a/ # a8a, a-a&lt;br /&gt;/a[6-C]a/ # a6a, a7a ... aCa characters from the ASCII table: 6789:;&lt;=&gt;?@ABC&lt;br /&gt;/a[C-6]a/ # syntax error&lt;br /&gt;/a[^xa]a/ # "aba", "aca" but not "aaa", "axa" what about "aa" ?&lt;br /&gt;# ^ as the first character in a character class means&lt;br /&gt;# a character that is not in the list&lt;br /&gt;/a[a^x]a/ # aaa, a^a, axa&lt;br /&gt;11.19. Special character classes&lt;br /&gt;Table 11-2. Special character classes&lt;br /&gt;Expression Meaning&lt;br /&gt;\w Word characters: [a-zA-Z0-9_] (but \w is locale&lt;br /&gt;dependent)&lt;br /&gt;\d Digits: [0-9]&lt;br /&gt;\s [\f\t\n\r ] form-feed, tab, newline, carriage return&lt;br /&gt;and SPACE&lt;br /&gt;\W [^\w]&lt;br /&gt;\D [^\d]&lt;br /&gt;\S [^\s]&lt;br /&gt;[:class:] POSIX character classes (alpha, alnum...)&lt;br /&gt;\p{...} Unicode definitions (IsAlpha, IsLower, IsHebrew,&lt;br /&gt;...)&lt;br /&gt;See also perldoc perlre and perldoc perluniintro&lt;br /&gt;11.20. Exercise: Number&lt;br /&gt;Write a function that given a string it return true if the string is a number.&lt;br /&gt;First define what do you mean by a number?&lt;br /&gt;Non negative integer?&lt;br /&gt;Integer?&lt;br /&gt;Real number?&lt;br /&gt;In scientific notation?&lt;br /&gt;7&lt;br /&gt;Chapter 11. Regular Expressions&lt;br /&gt;11.21. Exercise: Hex/Oct/Bin&lt;br /&gt;Write functions that return true if the given value is a&lt;br /&gt;1) Hexadecimal number&lt;br /&gt;2) Octal number&lt;br /&gt;3) Binary number&lt;br /&gt;11.22. Exercise: Roman numbers&lt;br /&gt;Write functions that return true if the given value is a Roman Number.&lt;br /&gt;If you can do that maybe write another function to return the decimal&lt;br /&gt;value of the given number.&lt;br /&gt;I, II, III, IV, V, VI, VII,....&lt;br /&gt;I = 1&lt;br /&gt;V = 5&lt;br /&gt;X = 10&lt;br /&gt;L = 50&lt;br /&gt;C = 100&lt;br /&gt;D = 500&lt;br /&gt;M = 1000&lt;br /&gt;11.23. Solution: Number&lt;br /&gt;Example 11-3. examples/regex/is_number.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;while (my $number = &lt;STDIN&gt;) {&lt;br /&gt;if (is_non_negative($number)) {&lt;br /&gt;print "non negative integer without +- sign\n"; # 0, 3, 7&lt;br /&gt;}&lt;br /&gt;if (is_integer($number)) {&lt;br /&gt;print "integer with optional +- sign\n"; # -1, +3&lt;br /&gt;}&lt;br /&gt;if (is_real($number)) {&lt;br /&gt;print "real number with decimal point\n"; # 3.1, 0.0, .3, 2., -.7&lt;br /&gt;}&lt;br /&gt;if (is_exp($number)) {&lt;br /&gt;print "exponential format\n"; # .1e&lt;br /&gt;}&lt;br /&gt;if (is_exp2($number)) {&lt;br /&gt;print "exponential format (x)\n"; # .1e&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;8&lt;br /&gt;Chapter 11. Regular Expressions&lt;br /&gt;sub is_non_negative { $_[0] =~ /^\d+$/ }&lt;br /&gt;sub is_integer { $_[0] =~ /^[+-]?\d+$/ }&lt;br /&gt;sub is_real { $_[0] =~ /\d/ and $_[0] =~ /^[+-]?\d*\.?\d*$/}&lt;br /&gt;sub is_exp { $_[0] =~ /\d/ and $_[0] =~ /^[+-]?\d*\.?\d*(e[+-]?\d+)?$/}&lt;br /&gt;sub is_exp2 { $_[0] =~ /\d/ and $_[0] =~ /^&lt;br /&gt;[+-]? # optional + or - sign&lt;br /&gt;\d* # 0 or more digits before the decimal point&lt;br /&gt;\.? # optional decimal point&lt;br /&gt;\d* # 0 or more digits after the decimal point&lt;br /&gt;(e[+-]?\d+)? # optional "e" followed by an integer number&lt;br /&gt;$/x}&lt;br /&gt;11.24. Solution: Hex/Oct/Bin&lt;br /&gt;Example 11-4. examples/regex/is_base_number.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;while (my $number = &lt;STDIN&gt;) {&lt;br /&gt;if (is_hex($number)) {&lt;br /&gt;print "Hexadecimal number\n"; # 0xAD37F&lt;br /&gt;}&lt;br /&gt;if (is_octal($number)) {&lt;br /&gt;print "Octal number\n"; # 02432471&lt;br /&gt;}&lt;br /&gt;if (is_binary($number)) {&lt;br /&gt;print "Binary number\n"; # 0b01110&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;sub is_hex { $_[0] =~ /^0x[\da-fA-F]+$/ }&lt;br /&gt;sub is_octal { $_[0] =~ /^0[0-7]+$/ }&lt;br /&gt;sub is_binary { $_[0] =~ /^0b[01]+$/ }&lt;br /&gt;11.25. Solution: Roman numbers&lt;br /&gt;Example 11-5. examples/regex/is_roman_number.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;while (my $number = &lt;STDIN&gt;) {&lt;br /&gt;# This solution only check is the string consists of characters used in as Roman numbers&lt;br /&gt;9&lt;br /&gt;Chapter 11. Regular Expressions&lt;br /&gt;# but does not check if the number is actually a valid number. (e.g. IVI is not valid)&lt;br /&gt;# I yet to see a definition on how to validate a Roman number.&lt;br /&gt;if (is_roman($number)) {&lt;br /&gt;print "Roman number\n";&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;sub is_roman { $_[0] =~ /^[IVXLCDM]+$/ }&lt;br /&gt;sub is_roman2 { $_[0] =~ /^(M{0,4})(CM|CD|D?C{0,3})(XL|XC|L?X{0,3})(IV|IX|V?I{0,3})$/ }&lt;br /&gt;11.26. Regexp::Common&lt;br /&gt;Example 11-6. examples/regex/regexp_common.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;use Regexp::Common;&lt;br /&gt;my $file = ’regexp_common.txt’;&lt;br /&gt;if (@ARGV) {&lt;br /&gt;$file = shift;&lt;br /&gt;}&lt;br /&gt;open(my $data, ’&lt;’, $file) or die "Could not open $file\n";&lt;br /&gt;while (my $line = &lt;$data&gt;) {&lt;br /&gt;chomp $line;&lt;br /&gt;print "LINE: ’$line’";&lt;br /&gt;if ($line =~ /$RE{balanced}{-parens=&gt;’()’}/) {&lt;br /&gt;print " balanced parentheses";&lt;br /&gt;}&lt;br /&gt;if ($line =~ /^$RE{lingua}{palindrome}$/) {&lt;br /&gt;print " a palindrome";&lt;br /&gt;}&lt;br /&gt;if ($line =~ /$RE{profanity}/) {&lt;br /&gt;print " a four letter word";&lt;br /&gt;}&lt;br /&gt;print "\n";&lt;br /&gt;}&lt;br /&gt;Example 11-7. examples/regex/regexp_common.txt&lt;br /&gt;one&lt;br /&gt;(two)&lt;br /&gt;(three))&lt;br /&gt;((three)&lt;br /&gt; 80&lt;br /&gt;Chapter 11. Regular Expressions&lt;br /&gt;)four(&lt;br /&gt;poop&lt;br /&gt;11.27. Options and modifiers&lt;br /&gt;// is actually the same as m//&lt;br /&gt;When using the m sign you can change the delimiters:&lt;br /&gt;Let’s say you would like to match lines with&lt;br /&gt;/usr/bin/perl&lt;br /&gt;if ($line =~ /\/usr\/bin\/perl/) {&lt;br /&gt;}&lt;br /&gt;if ($line =~ m{/usr/bin/perl}) {&lt;br /&gt;}&lt;br /&gt;11.28. /i Case sensitivity&lt;br /&gt;$line = "Apple";&lt;br /&gt;/apple/ # does not match&lt;br /&gt;/apple/i # case insensitive will match&lt;br /&gt;11.29. /m multiple lines&lt;br /&gt;^ will match beginning of line&lt;br /&gt;$ will match end of line&lt;br /&gt;\A still matches beginning of string&lt;br /&gt;\z&lt;br /&gt;\Z&lt;br /&gt;Example 11-8. examples/regex/find_letter_change.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;#../regex/examples/text/american-english&lt;br /&gt;my $filename = shift or die;&lt;br /&gt;my $data;&lt;br /&gt;{&lt;br /&gt; 81&lt;br /&gt;Chapter 11. Regular Expressions&lt;br /&gt;open my $fh, ’&lt;’, $filename or die;&lt;br /&gt;local $/ = undef;&lt;br /&gt;$data = &lt;$fh&gt;&lt;br /&gt;}&lt;br /&gt;if ($data =~ /(^a.*\nb.*\n)/mi) {&lt;br /&gt;print $1;&lt;br /&gt;}&lt;br /&gt;11.30. /s single line&lt;br /&gt;. will match any character (including newline)&lt;br /&gt;11.31. /x enable whitespaces and comments&lt;br /&gt;/(X\d+).*\1/&lt;br /&gt;/&lt;br /&gt;(X\d+) # product number&lt;br /&gt;.* # any character&lt;br /&gt;\1 # the same product number&lt;br /&gt;/x&lt;br /&gt;11.32. Substitute&lt;br /&gt;• s/PATTERN/REPLACEMENT/&lt;br /&gt;$line = "abc123def";&lt;br /&gt;$line =~ s/\d+/ /; # "abc def"&lt;br /&gt;$line =~ s/([a-z]*)(\d*)([a-z]*)/$3$2$1/; # "def123abc"&lt;br /&gt;$line =~ s/.../x/; # "x123def";&lt;br /&gt;$line =~ s/.../x/g; # "xxx";&lt;br /&gt;$line =~ s/(.)(.)/$2$1/; # "bac123def"&lt;br /&gt;$line =~ s/(.)(.)/$2$1/g; # "ba1c32edf"&lt;br /&gt; 82&lt;br /&gt;Chapter 11. Regular Expressions&lt;br /&gt;11.33. Greedy quantifiers&lt;br /&gt;/xa*/ on xaaab&lt;br /&gt;/xa*/ on xabxaab&lt;br /&gt;/a*/ on xabxaab&lt;br /&gt;11.34. minimal match&lt;br /&gt;/a.*b/ axbzb matches axbzb&lt;br /&gt;/a.*?b/ axbzb matches axb as the * quantifier is minimal now&lt;br /&gt;/a.*b/ axy121413413bq&lt;br /&gt;/a.*?b/ axy121413413bq&lt;br /&gt;They both match the same string&lt;br /&gt;11.35. Replace spaces&lt;br /&gt;s/^\s*// leading&lt;br /&gt;s/\s*$// tailing&lt;br /&gt;Better to write:&lt;br /&gt;s/^\s+// leading&lt;br /&gt;s/\s+$// tailing&lt;br /&gt;both ends:&lt;br /&gt;s/^\s*(.*)\s*$/$1/ " abc " =&gt; "abc " because of the greediness&lt;br /&gt;s/^\s*(.*?)\s*$/$1/ " abc " =&gt; "abc" minimal match&lt;br /&gt;11.36. Replace string in assembly code&lt;br /&gt;Example 11-9. examples/regex/assembly_source.txt&lt;br /&gt;mv A, R3&lt;br /&gt;mv R2, B&lt;br /&gt;mv R1, R3&lt;br /&gt;mv B, R4&lt;br /&gt;add A, R1&lt;br /&gt;add B, R1&lt;br /&gt;add R1, R2&lt;br /&gt;add R3, R3&lt;br /&gt;mv X, R2&lt;br /&gt; 83&lt;br /&gt;Chapter 11. Regular Expressions&lt;br /&gt;Example 11-10. examples/regex/assembly_process.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;# assuming there are no R4 values then 4 substitutions will do&lt;br /&gt;s/R1/R4/g&lt;br /&gt;s/R3/R1/g&lt;br /&gt;s/R2/R3/g&lt;br /&gt;s/R4/R2/g&lt;br /&gt;# or without any assumption and in one substitution:&lt;br /&gt;my %map = (&lt;br /&gt;R1 =&gt; ’R2’,&lt;br /&gt;R2 =&gt; ’R3’,&lt;br /&gt;R3 =&gt; ’R1’,&lt;br /&gt;);&lt;br /&gt;s/(R[123])/$map{$1}/g&lt;br /&gt;11.37. split with regular expresion&lt;br /&gt;LIST = split REGEX, STRING;&lt;br /&gt;Example 11-11. examples/regex/field_value_pairs.txt&lt;br /&gt;fname = Foo&lt;br /&gt;lname = Bar&lt;br /&gt;email=foo@bar.com&lt;br /&gt;Example 11-12. examples/regex/parse_field_value_pairs.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;# data: field_value_pairs.txt&lt;br /&gt;my $filename = shift or die "Usage: $0 filename\n";&lt;br /&gt;open(my $fh, "&lt;", $filename) or die "Could not open ’$filename’\n";&lt;br /&gt;while (my $line = &lt;$fh&gt;) {&lt;br /&gt;chomp $line;&lt;br /&gt;my ($field, $value) = split /\s*=\s*/, $line;&lt;br /&gt;print "$value=$field\n";&lt;br /&gt;}&lt;br /&gt; 84&lt;br /&gt;Chapter 11. Regular Expressions&lt;br /&gt;11.38. Exercise: split CGI&lt;br /&gt;Given a string that looks like this:&lt;br /&gt;my $str = ’fname=Foo&amp;lname=Bar&amp;email=foo@bar.com’;&lt;br /&gt;Create a hash where the keys are fname, lname, email&lt;br /&gt;11.39. Exercies: filename/dirname&lt;br /&gt;Give a path like /home/foo/.mozilla/cache/data.txt&lt;br /&gt;return the filename (data.txt)&lt;br /&gt;return the full-path directory name ( /home/foo/.mozilla/cache )&lt;br /&gt;11.40. Exercise: Sort SNMP numbers&lt;br /&gt;Given a file with SNMP numbers (one number on every line)&lt;br /&gt;print them in sorted order comparing the first number of&lt;br /&gt;each SNMP number first.&lt;br /&gt;If they are equal then comparing the second number, etc...&lt;br /&gt;Example 11-13. examples/regex/snmp.txt&lt;br /&gt;1.2.7.6&lt;br /&gt;4.5.7.23&lt;br /&gt;1.2.7&lt;br /&gt;2.3.5.7.10.8.9&lt;br /&gt;11.41. Exercise: parse hours log file and give report&lt;br /&gt;The log file looks like this&lt;br /&gt;Example 11-14. examples/regex/timelog.log&lt;br /&gt;09:20 Introduction&lt;br /&gt;11:00 Exercises&lt;br /&gt;11:15 Break&lt;br /&gt;11:35 Scalars&lt;br /&gt;12:30 Lunch Break&lt;br /&gt;13:30 Exercises&lt;br /&gt;14:10 Solutions&lt;br /&gt;14:30 Break&lt;br /&gt; 85&lt;br /&gt;Chapter 11. Regular Expressions&lt;br /&gt;14:40 Arrays&lt;br /&gt;15:40 Exercises&lt;br /&gt;17:00 Solutions&lt;br /&gt;17:30 End&lt;br /&gt;09:30 Advanced Arrays&lt;br /&gt;10:30 Break&lt;br /&gt;10:50 Exercises&lt;br /&gt;12:00 Solutions&lt;br /&gt;12:30 Hash fuction introduction&lt;br /&gt;12:45 Lunch Break&lt;br /&gt;14:15 Exercises&lt;br /&gt;16:00 Solutions&lt;br /&gt;16:15 Break&lt;br /&gt;16:30 Subroutines&lt;br /&gt;17:00 Exercises&lt;br /&gt;17:30 End&lt;br /&gt;the report should look something like this:&lt;br /&gt;09:20-11:00 Introduction&lt;br /&gt;11:00-11:15 Exercises&lt;br /&gt;11:15-11:35 Break&lt;br /&gt;...&lt;br /&gt;Solutions 95 minutes 9%&lt;br /&gt;Break 65 minutes 6%&lt;br /&gt;...&lt;br /&gt;11.42. Exercise: Parse ini file&lt;br /&gt;An ini file has sections starting by the name of the section in square brackets and within&lt;br /&gt;each section there are key = value pairs with optional spaces around the "=" sign.&lt;br /&gt;The keys can only contain letters, numbers, underscore or dash.&lt;br /&gt;In addition there can be empty lines and lines starting with # which are comments.&lt;br /&gt;Given a filename, a section name and a key, please print out the value.&lt;br /&gt;Example ini file:&lt;br /&gt;Example 11-15. examples/regex/inifile.ini&lt;br /&gt;# comment&lt;br /&gt;[alpha]&lt;br /&gt;base= moon&lt;br /&gt;ship= alpha 3&lt;br /&gt; 86&lt;br /&gt;Chapter 11. Regular Expressions&lt;br /&gt;[earth]&lt;br /&gt;# ?&lt;br /&gt;base=earth&lt;br /&gt;ship= x-wing&lt;br /&gt;11.43. Exercise: parse perl file&lt;br /&gt;Parse your perl files and print out the names of your variables.&lt;br /&gt;In the first version print out the scalar variables only.&lt;br /&gt;In the second version show all variables.&lt;br /&gt;(you give the names of the files on the command line)&lt;br /&gt;11.44. Solution: Split CGI&lt;br /&gt;Example 11-16. examples/regex/split_cgi.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my $str = ’fname=Foo&amp;lname=Bar&amp;email=foo@bar.com’;&lt;br /&gt;my %data = split /[=&amp;]/, $str;&lt;br /&gt;use Data::Dumper;&lt;br /&gt;print Dumper \%data;&lt;br /&gt;11.45. Solution: filename/dirname&lt;br /&gt;Example 11-17. examples/regex/file_basename.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my $path = "/home/foo/.mozilla/cache/data.txt";&lt;br /&gt;my $filename = ($path =~ m{([^/]*)$} ? $1 : "");&lt;br /&gt;my $dirname = ($path =~ m{^(.*)/} ? $1 : "");&lt;br /&gt;# Directory name:&lt;br /&gt;print "$path\n";&lt;br /&gt; 87&lt;br /&gt;Chapter 11. Regular Expressions&lt;br /&gt;print "$filename\n";&lt;br /&gt;print "$dirname\n";&lt;br /&gt;use File::Basename;&lt;br /&gt;print basename($path) . "\n";&lt;br /&gt;print dirname($path) . "\n";&lt;br /&gt;11.46. Solution: Sort SNMP numbers&lt;br /&gt;Example 11-18. examples/regex/sort_snmp_numbers.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my $filename = shift or die "Usage: $0 filename\n";&lt;br /&gt;open(my $fh, "&lt;", $filename) or die "Could not open ’$filename’\n";&lt;br /&gt;my @snmps = &lt;$fh&gt;;&lt;br /&gt;chomp @snmps;&lt;br /&gt;print join "\n", @snmps;&lt;br /&gt;print "\n------------------\n";&lt;br /&gt;my @sorted_snmps = sort by_snmp_number @snmps;&lt;br /&gt;print join "\n", @sorted_snmps;&lt;br /&gt;sub by_snmp_number {&lt;br /&gt;my @a = split /\./, $a;&lt;br /&gt;my @b = split /\./, $b;&lt;br /&gt;foreach my $i (0..@a-1) {&lt;br /&gt;return 1 if $i &gt;= @b;&lt;br /&gt;next if $a[$i] == $b[$i];&lt;br /&gt;return $a[$i] &lt;=&gt; $b[$i];&lt;br /&gt;}&lt;br /&gt;return 0;&lt;br /&gt;}&lt;br /&gt;print "\n------------------\n";&lt;br /&gt;my @data = map { {"ip" =&gt; $_, "data" =&gt; [split /\./, $_]} } @snmps;&lt;br /&gt;my @sorted_data = sort {g($a, $b)} @data;&lt;br /&gt;my @sorted_snmps_take_two = map {$_-&gt;{ip}} @sorted_data;&lt;br /&gt;print join "\n", @sorted_snmps_take_two;&lt;br /&gt;print "\n------------------\n";&lt;br /&gt; 88&lt;br /&gt;Chapter 11. Regular Expressions&lt;br /&gt;sub g {&lt;br /&gt;my ($a, $b) = @_;&lt;br /&gt;my @a = @{ $a-&gt;{data} };&lt;br /&gt;my @b = @{ $b-&gt;{data} };&lt;br /&gt;foreach my $i (0..@a-1) {&lt;br /&gt;return 1 if $i &gt;= @b;&lt;br /&gt;next if $a[$i] == $b[$i];&lt;br /&gt;return $a[$i] &lt;=&gt; $b[$i];&lt;br /&gt;}&lt;br /&gt;return 0;&lt;br /&gt;}&lt;br /&gt;11.47. Solution: parse hours log file and give report&lt;br /&gt;Example 11-19. examples/regex/timelog.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my $filename = shift or die "Usage: $0 filename\n";&lt;br /&gt;my @entries;&lt;br /&gt;my %stat;&lt;br /&gt;open(my $fh, "&lt;", $filename) or die "Could not open ’$filename’ $!";&lt;br /&gt;while (my $line = &lt;$fh&gt;) {&lt;br /&gt;chomp $line;&lt;br /&gt;next if $line =~ /^#/;&lt;br /&gt;if ($line =~ /\S/) {&lt;br /&gt;push @entries, $line;&lt;br /&gt;next;&lt;br /&gt;}&lt;br /&gt;process_day();&lt;br /&gt;@entries = ();&lt;br /&gt;}&lt;br /&gt;process_day(); # in case there is no empty line after the last line&lt;br /&gt;foreach my $title (keys %stat) {&lt;br /&gt;printf "%-25s %4s minutes %3s%%\n",&lt;br /&gt;$title, $stat{$title}, int(100 * $stat{$title} / $stat{Total});&lt;br /&gt;}&lt;br /&gt;sub process_day {&lt;br /&gt; 89&lt;br /&gt;Chapter 11. Regular Expressions&lt;br /&gt;my @day;&lt;br /&gt;foreach my $e (@entries) {&lt;br /&gt;my ($time, $title) = split " ", $e, 2;&lt;br /&gt;if (@day) {&lt;br /&gt;$day[-1]{end} = $time;&lt;br /&gt;my ($start_hour, $start_min) = split ":", $day[-1]{start};&lt;br /&gt;my ($end_hour, $end_min) = split ":", $day[-1]{end};&lt;br /&gt;$day[-1]{total} = $end_hour*60+$end_min - ($start_hour*60+$start_min);&lt;br /&gt;if ($day[-1]{title} =~ /Break|Exercises|Solutions/) {&lt;br /&gt;$stat{$day[-1]{title}} += $day[-1]{total};&lt;br /&gt;} else {&lt;br /&gt;$stat{Lectures} += $day[-1]{total};&lt;br /&gt;}&lt;br /&gt;$stat{Total} += $day[-1]{total};&lt;br /&gt;print "$day[-1]{start}-$day[-1]{end} $day[-1]{title}\n";&lt;br /&gt;}&lt;br /&gt;if ($title ne "End") {&lt;br /&gt;push @day, {&lt;br /&gt;start =&gt; $time,&lt;br /&gt;title =&gt; $title,&lt;br /&gt;};&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;print "\n";&lt;br /&gt;return;&lt;br /&gt;}&lt;br /&gt;11.48. Solution: Parse ini file&lt;br /&gt;Example 11-20. examples/regex/parse_ini.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;if (@ARGV != 2) {&lt;br /&gt;print "Usage: $0 section key\n";&lt;br /&gt;exit;&lt;br /&gt;}&lt;br /&gt;my ($section, $key) = @ARGV;&lt;br /&gt;my $in_section = 0;&lt;br /&gt;while (my $line = &lt;STDIN&gt;) {&lt;br /&gt;next if $line =~ /^#/; # skip comments&lt;br /&gt;next if $line =~ /^\s*$/; # skip empty lines&lt;br /&gt;if ($line =~ /^\[$section\]$/) {&lt;br /&gt; 90&lt;br /&gt;Chapter 11. Regular Expressions&lt;br /&gt;$in_section = 1;&lt;br /&gt;next;&lt;br /&gt;}&lt;br /&gt;if ($line =~ /^\[/) {&lt;br /&gt;$in_section = 0;&lt;br /&gt;next;&lt;br /&gt;}&lt;br /&gt;if ($in_section and $line =~ /^$key\s*=\s*(.*)$/) {&lt;br /&gt;print "$1\n";&lt;br /&gt;last;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;11.49. Solution: parse perl file&lt;br /&gt;Example 11-21. examples/regex/print_variables.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;# scalars only but finds only the first variable on every line&lt;br /&gt;#while (&lt;&gt;) {&lt;br /&gt;# if (/(\$\w+)\b/) {&lt;br /&gt;# if (not defined $h{$ARGV}{$1}) {&lt;br /&gt;# $h{$ARGV}{$1}=1;&lt;br /&gt;# print "$ARGV: $1\n";&lt;br /&gt;# }&lt;br /&gt;# }&lt;br /&gt;#}&lt;br /&gt;# scalars $ or arrays @ or hashes %&lt;br /&gt;# including all variables on every line&lt;br /&gt;my %h;&lt;br /&gt;while (my $line = &lt;&gt;) {&lt;br /&gt;if (my @vars = $line =~/[\$@%]\w+\b/g) {&lt;br /&gt;foreach my $v (@vars) {&lt;br /&gt;if (not defined $h{$ARGV}{$v}) {&lt;br /&gt;$h{$ARGV}{$v}=1;&lt;br /&gt;print "$ARGV: $v\n";&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt; 91&lt;br /&gt;Chapter 11. Regular Expressions&lt;br /&gt;11.50. Regular Expressions Cheat sheet&lt;br /&gt;Table 11-3. Regexes&lt;br /&gt;Expression Meaning&lt;br /&gt;a Just an ’a’ character&lt;br /&gt;. any character except new-line&lt;br /&gt;[bgh.] one of the characters listed in the character class&lt;br /&gt;b,g,h or .&lt;br /&gt;[b-h] The same as [bcdefgh]&lt;br /&gt;[a-z] Lower case letters&lt;br /&gt;[b-] The letter b or -&lt;br /&gt;[^bx] Anything except b or x&lt;br /&gt;\w Word characters: [a-zA-Z0-9_]&lt;br /&gt;\d Digits: [0-9]&lt;br /&gt;\s [\f\t\n\r ] form-feed, tab, newline, carriage return&lt;br /&gt;and SPACE&lt;br /&gt;\W [^\w]&lt;br /&gt;\D [^\d]&lt;br /&gt;\S [^\s]&lt;br /&gt;[:class:] POSIX character classes (alpha, alnum...)&lt;br /&gt;\p{...} Unicode definitions (IsAlpha, IsLower, IsHebrew,&lt;br /&gt;...)&lt;br /&gt;a* 0-infinite ’a’ characters&lt;br /&gt;a+ 1-infinite ’a’ characters&lt;br /&gt;a? 0-1 ’a’ characters&lt;br /&gt;a{n,m} n-m ’a’ characters&lt;br /&gt;( ) Grouping and capturing&lt;br /&gt;| Alternation&lt;br /&gt;\1, \2 Capture buffers&lt;br /&gt;$1, $2 Capture variables&lt;br /&gt;^ $ Beginning and end of string ancors&lt;br /&gt;See also perldoc perlre&lt;br /&gt; 92&lt;br /&gt;Chapter 12. Shell to Perl&lt;br /&gt;Manipulating Files and Directories&lt;br /&gt;12.1. Running External Programs&lt;br /&gt;system() can execute any external program. You pass to it the same string as you would type on the&lt;br /&gt;command line.&lt;br /&gt;It returns 0 on success and the exit code of the external program on failure. Hence the strange way we&lt;br /&gt;check if it failes.&lt;br /&gt;Passing the program name and the parameters as an array is more secure as it does not involve invocation&lt;br /&gt;of a shell. There is no shell processing involved;&lt;br /&gt;system("some_app.exe --option");&lt;br /&gt;See perldoc -f system for more error handling&lt;br /&gt;my $result = ‘some_app.exe --option‘;&lt;br /&gt;my @result = ‘some_app.exe --option‘;&lt;br /&gt;backticks “ are also know as qx{}&lt;br /&gt;12.2. UNIX commands from the inside&lt;br /&gt;You can run every external command using system&lt;br /&gt;but it makes it platform dependant and might have more security implications.&lt;br /&gt;The following calls are available from Perl.&lt;br /&gt;&lt;br /&gt;There are more but we won’t cover them now.&lt;br /&gt;Table 12-1. UNIX command&lt;br /&gt;UNIX DOS&lt;br /&gt;unlink FILENAME rm del&lt;br /&gt;rename OLDFILE, NEWFILE mv ren&lt;br /&gt;chmod MODE, FILE chmod -&lt;br /&gt;chown UID, GID, FILE chown -&lt;br /&gt;93&lt;br /&gt;Chapter 12. Shell to Perl&lt;br /&gt;chdir DIRNAME cd cd&lt;br /&gt;mkdir DIRNAME, PERM mkdir mkdir&lt;br /&gt;rmdir DIRNAME rmdir rmdir&lt;br /&gt;link OLDNAME,&lt;br /&gt;NEWNAME&lt;br /&gt;ln -&lt;br /&gt;symlink OLDNAME,&lt;br /&gt;NEWNAME&lt;br /&gt;ln -s -&lt;br /&gt;readlink LINKNAME ls -l -&lt;br /&gt;glob WILDCARDS ls -1 dir&lt;br /&gt;opendir, readdir ls -1 dir&lt;br /&gt;%ENV, $ENV{HOME}&lt;br /&gt;my $uid = getpwnam($username);&lt;br /&gt;my $gid = getgrnam($groupname);&lt;br /&gt;12.3. File globbing (wildcards)&lt;br /&gt;Example 12-1. examples/shell/file_globbing.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;# File globbing&lt;br /&gt;my @xml_files_in_current_dir = glob "*.xml";&lt;br /&gt;my $bin_dir = "/home/foo/bin";&lt;br /&gt;my @perl_files = glob "$bin_dir/*.pl $bin_dir/*.pm";&lt;br /&gt;# my @xml_files_using_old_syntax = &lt;*.xml&gt;;&lt;br /&gt;12.4. Rename files&lt;br /&gt;• glob - directory listing&lt;br /&gt;Example 12-2. examples/shell/rename_files.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;foreach my $file (glob "*.xml") {&lt;br /&gt; 94&lt;br /&gt;Chapter 12. Shell to Perl&lt;br /&gt;my $new = substr($file, 0, -3) . "html";&lt;br /&gt;print "rename $file, $new\n";&lt;br /&gt;#rename $file, $new;&lt;br /&gt;}&lt;br /&gt;12.5. Directory handles&lt;br /&gt;For a platform independent approach use opendir and readdir.&lt;br /&gt;In order to read the content of a directory (that is the list of the files)&lt;br /&gt;first we have to open the directory similarly to the way we opened a file&lt;br /&gt;but using the opendir function&lt;br /&gt;This way we get a directory handle which we can use in subsequent operations.&lt;br /&gt;Once the directory was opened successfully we can use the function readdir&lt;br /&gt;in a loop to get the names of the files in that directory&lt;br /&gt;Example 12-3. examples/shell/list_directory.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my $dir = shift or die "Usage: $0 DIRECTORY\n";&lt;br /&gt;opendir my $dh, $dir or die "Cannot open $dir: $!\n";&lt;br /&gt;while (my $entry = readdir $dh) {&lt;br /&gt;if ($entry eq "." or $entry eq "..") {&lt;br /&gt;next;&lt;br /&gt;}&lt;br /&gt;print "$entry\n";&lt;br /&gt;}&lt;br /&gt;closedir $dh;&lt;br /&gt;in LIST context readdir returns all the files in the directory.&lt;br /&gt;opendir(my $dh, "/etc") or die $!;&lt;br /&gt;@files = readdir $dh;&lt;br /&gt;12.6. File::HomeDir&lt;br /&gt;Example 12-4. examples/shell/file_homedir.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt; 95&lt;br /&gt;Chapter 12. Shell to Perl&lt;br /&gt;use warnings;&lt;br /&gt;use File::HomeDir;&lt;br /&gt;my $home = File::HomeDir-&gt;my_home;&lt;br /&gt;my $docs = File::HomeDir-&gt;my_documents;&lt;br /&gt;print "$home\n";&lt;br /&gt;print "$docs\n";&lt;br /&gt;12.7. More UNIX commands implemented in modules&lt;br /&gt;Table 12-2. UNIX command in Modules&lt;br /&gt;Module Usage Comment&lt;br /&gt;Cwd $dir = cwd; current working directory&lt;br /&gt;File::Copy copy "oldfile", "newfile";&lt;br /&gt;move "oldfile", "newfile"; this works between file systems&lt;br /&gt;as well&lt;br /&gt;File::Basename basename "/a/b/c/file.pl"; file.pl&lt;br /&gt;dirname "/a/b/c/file.pl"; /a/b/c&lt;br /&gt;File::Path mkpath("a/b/c")&lt;br /&gt;rmtree("/")&lt;br /&gt;File::Find&lt;br /&gt;File::Find::Rule&lt;br /&gt;12.8. More modules&lt;br /&gt;use File::Spec;&lt;br /&gt;$f = File::Spec-&gt;catfile(’home’, ’admin’, ’project’); # fancy OOP style&lt;br /&gt;print "$f\n"; # home\admin\project on Windows&lt;br /&gt;use File::Spec::Functions; # build path based on current Os&lt;br /&gt;$f = catfile(’home’, ’admin’, ’project’);&lt;br /&gt;print "$f\n"; # home/admin/project on Unix&lt;br /&gt;12.9. Change Copyright text in every source file in a&lt;br /&gt; 96&lt;br /&gt;Chapter 12. Shell to Perl&lt;br /&gt;directory hierarchy&lt;br /&gt;• File::Find&lt;br /&gt;• reference to subroutine&lt;br /&gt;Example 12-5. examples/shell/change_files.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;use File::Find qw(find);&lt;br /&gt;my $dir = ".";&lt;br /&gt;if (defined $ARGV[0]) {&lt;br /&gt;$dir = $ARGV[0];&lt;br /&gt;}&lt;br /&gt;find( \&amp;change_file, $dir);&lt;br /&gt;sub change_file {&lt;br /&gt;if (not -f $_) {&lt;br /&gt;return;&lt;br /&gt;}&lt;br /&gt;if (substr($_, -3) ne ".pl") {&lt;br /&gt;return;&lt;br /&gt;}&lt;br /&gt;print "$_\n";&lt;br /&gt;my $data;&lt;br /&gt;if (open my $fh, "&lt;", $_) {&lt;br /&gt;local $/ = undef;&lt;br /&gt;$data = &lt;$fh&gt;;&lt;br /&gt;} else {&lt;br /&gt;warn "Could not open ’$_’ for reading\n";&lt;br /&gt;return;&lt;br /&gt;}&lt;br /&gt;$data =~ s/Copyright Old/Coyright New/g;&lt;br /&gt;# Let’s not ruin our example files....&lt;br /&gt;my $new_name = "$_.new";&lt;br /&gt;if (open my $fh, "&gt;", $new_name) {&lt;br /&gt;print $fh $data;&lt;br /&gt;} else {&lt;br /&gt;warn "Could not open ’$new_name’ for writing\n";&lt;br /&gt;}&lt;br /&gt;return;&lt;br /&gt;}&lt;br /&gt; 97&lt;br /&gt;Chapter 12. Shell to Perl&lt;br /&gt;12.10. File::Tools&lt;br /&gt;Includes all the above&lt;br /&gt;12.11. Exercise: Tree&lt;br /&gt;Implement tree: prints a tree structure of a given directory.&lt;br /&gt;All filenames are printed and subdirectories are properly indented.&lt;br /&gt;$ tree.pl .&lt;br /&gt;.&lt;br /&gt;subdir_1&lt;br /&gt;file_1_in_subdir_1&lt;br /&gt;file_2_in_subdir_1&lt;br /&gt;subdir_2&lt;br /&gt;subdir_2_1&lt;br /&gt;file_1_in_subdir_2_1&lt;br /&gt;file_1_in_subdir_2&lt;br /&gt;Implement the previous one using File::Find&lt;br /&gt;Implement the previous one using File::Find::Rule&lt;br /&gt;12.12. Solutions: Tree&lt;br /&gt;Example 12-6. examples/shell/tree.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my $dir = ’.’;&lt;br /&gt;if (@ARGV) {&lt;br /&gt;$dir = $ARGV[0];&lt;br /&gt;}&lt;br /&gt;traverse_dir(”, $dir, 0);&lt;br /&gt;sub traverse_dir {&lt;br /&gt;my ($dir, $thing, $depth) = @_;&lt;br /&gt;my $path = ($dir ? "$dir/$thing" : $thing);&lt;br /&gt; 98&lt;br /&gt;Chapter 12. Shell to Perl&lt;br /&gt;print " " x ($depth*3), "$thing\n";&lt;br /&gt;return if not -d $path;&lt;br /&gt;if (opendir my $dh, $path) {&lt;br /&gt;while (my $entry = readdir $dh) {&lt;br /&gt;next if $entry eq "." or $entry eq "..";&lt;br /&gt;traverse_dir ($path, $entry, $depth+1);&lt;br /&gt;}&lt;br /&gt;} else {&lt;br /&gt;print " " x ($depth*3-3), "#### Could not open $dir\n";&lt;br /&gt;}&lt;br /&gt;return;&lt;br /&gt;}&lt;br /&gt;Example 12-7. examples/shell/tree_ff.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;use File::Find;&lt;br /&gt;if (not @ARGV) {&lt;br /&gt;@ARGV = (".");&lt;br /&gt;}&lt;br /&gt;find (\&amp;find_name, @ARGV);&lt;br /&gt;sub find_name {&lt;br /&gt;print " " x (split("/", $File::Find::name) -1);&lt;br /&gt;print "$_\n";&lt;br /&gt;return;&lt;br /&gt;}&lt;br /&gt;Example 12-8. examples/shell/tree_file_find_rule.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;use File::Find::Rule;&lt;br /&gt;my $dir = ’.’;&lt;br /&gt;if (@ARGV) {&lt;br /&gt;$dir = shift;&lt;br /&gt;}&lt;br /&gt;foreach my $thing (File::Find::Rule-&gt;in($dir)) {&lt;br /&gt;my @parts = split m{/}, $thing;&lt;br /&gt;print " " x @parts;&lt;br /&gt;print "$parts[-1]\n";&lt;br /&gt;}&lt;br /&gt; 99&lt;br /&gt;Chapter 13. More about files&lt;br /&gt;13.1. File test or -X operators&lt;br /&gt;Before we try to read from a file or try to write to a file&lt;br /&gt;we might want to check our rights, if we can do the required action at all.&lt;br /&gt;For this there is a bunch of so called -X operators. Usually you use them in&lt;br /&gt;an if statement:&lt;br /&gt;if (-e "file.txt") {&lt;br /&gt;print "File exists !\n";&lt;br /&gt;}&lt;br /&gt;• -e File (or directory) exists&lt;br /&gt;• -r File (or directory) is readable by this user&lt;br /&gt;• -w File (or directory) is writable by this user&lt;br /&gt;• -x File (or directory) is executable by this user&lt;br /&gt;• -d Entry is a directory&lt;br /&gt;• -l Entry is a symbolic link&lt;br /&gt;• -s Size of the file (hence also means ’file is not empty’)&lt;br /&gt;• -M Number of days between the modification date of a file and the start time of our script&lt;br /&gt;Hence -s can be used either in an if statement or like this:&lt;br /&gt;$size = -s $filename;&lt;br /&gt;There are more such operators see perldoc -f -x&lt;br /&gt;13.2. Reading from file, read, eof&lt;br /&gt;Once the file is open for reading it behaves exactly like STDIN and we can access the same way.&lt;br /&gt;Example 13-1. examples/files/read_from_file.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my $filename = "input.txt";&lt;br /&gt;open my $fh, "&lt;", $filename or die $!;&lt;br /&gt;100&lt;br /&gt;Chapter 13. More about files&lt;br /&gt;my $line = &lt;$fh&gt;;&lt;br /&gt;chomp $line;&lt;br /&gt;while (my $line = &lt;$fh&gt;) {&lt;br /&gt;chomp $line;&lt;br /&gt;#...&lt;br /&gt;}&lt;br /&gt;open my $data, "&lt;", $filename or die $!;&lt;br /&gt;my @lines = &lt;$data&gt;;&lt;br /&gt;chomp @lines;&lt;br /&gt;foreach my $line (@lines) {&lt;br /&gt;print $line;&lt;br /&gt;}&lt;br /&gt;In Perl we usually care about lines of input so the above is enough.&lt;br /&gt;Still some like to read files with chunks of arbitrary length.&lt;br /&gt;read puts the read string to the variable passed to the function and&lt;br /&gt;returns the number of characters actually read&lt;br /&gt;READ_LENGTH = read FILEHANDLE,SCALAR,LENGTH&lt;br /&gt;Example 13-2. examples/files/read_file.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;# reading in 30 characters:&lt;br /&gt;open my $in, "&lt;", $0 or die $!;&lt;br /&gt;my $expected = 30;&lt;br /&gt;my $buf;&lt;br /&gt;my $actual = read $in, $buf, $expected;&lt;br /&gt;if ($actual &lt; $expected) {&lt;br /&gt;print "reached end of file\n";&lt;br /&gt;}&lt;br /&gt;# returns TRUE if we are stand at or after the end of file.&lt;br /&gt;eof($in)&lt;br /&gt;13.3. tell, seek&lt;br /&gt;For our purposes a file is a line of characters.&lt;br /&gt;After a bunch of read and/or write operations we need to tell where are we on that line ?&lt;br /&gt; 101&lt;br /&gt;Chapter 13. More about files&lt;br /&gt;LOCATION = tell FILEHANDLE&lt;br /&gt;We might also want to move within that file&lt;br /&gt;seek FILEHANDLE, OFFSET, WHENCE&lt;br /&gt;WHENCE:&lt;br /&gt;0 from beginning of file&lt;br /&gt;1 from current location&lt;br /&gt;2 from end of file&lt;br /&gt;OFFSET:&lt;br /&gt;+/- number of bytes to move&lt;br /&gt;the important values are:&lt;br /&gt;seek $fh, 0,0; # go to the beginning of the file&lt;br /&gt;seek $fh, 0,2; # go to the end of the file&lt;br /&gt;13.4. truncate&lt;br /&gt;# Sometimes you need to&lt;br /&gt;truncate FILEHANDLE, LENGTH;&lt;br /&gt;Example 13-3. examples/files/truncate.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my $new = $ARGV[0];&lt;br /&gt;my $filename = "file.txt";&lt;br /&gt;open my $fh, "+&lt;", $filename or die "Could not open $!\n";&lt;br /&gt;my $old = &lt;$fh&gt;;&lt;br /&gt;seek $fh, 0, 0; # move to the beginning of the file&lt;br /&gt;print $fh $new;&lt;br /&gt;truncate $fh, length $new; # cut the file to the new size&lt;br /&gt;13.5. UNIX file system, hard links symbolic links&lt;br /&gt;• What is in a Directory ?&lt;br /&gt;• What is in an Inode ?&lt;br /&gt; 102&lt;br /&gt;Chapter 13. More about files&lt;br /&gt;• What is a symbolic link ?&lt;br /&gt;• What is a hard link ?&lt;br /&gt;What links can be between different partitions ?&lt;br /&gt;(hint: only symbolic links as hard links are bound to the inode&lt;br /&gt;number which is local to each partition)&lt;br /&gt;13.6. stat, lstat&lt;br /&gt;# In order to get information from the inode table you can use the stat system call&lt;br /&gt;ARRAY = stat FILEHANDLE| FILENAME&lt;br /&gt;@fields = stat ($filename);&lt;br /&gt;@fields = stat ($fh);&lt;br /&gt;$fields[4] is the UID&lt;br /&gt;$fields[7] is the size in bytes&lt;br /&gt;0 dev device number of file system&lt;br /&gt;1 ino inode number&lt;br /&gt;2 mode file mode (type and permissions)&lt;br /&gt;3 nlink number of (hard) links to the file&lt;br /&gt;4 uid numeric user ID of file’s owner&lt;br /&gt;5 gid numeric group ID of file’s owner&lt;br /&gt;6 rdev the device identifier (special files only)&lt;br /&gt;7 size total size of file, in bytes&lt;br /&gt;8 atime last access time in seconds since the epoch&lt;br /&gt;9 mtime last modify time in seconds since the epoch&lt;br /&gt;10 ctime inode change time (NOT creation time!) in seconds since the epoch&lt;br /&gt;11 blksize preferred block size for file system I/O&lt;br /&gt;12 blocks actual number of blocks allocated&lt;br /&gt;for symbolic links use lstat&lt;br /&gt;13.7. Exercise: Create a counter&lt;br /&gt;Each time I run the script I want to get a higher number.&lt;br /&gt; 103&lt;br /&gt;Chapter 13. More about files&lt;br /&gt;13.8. Exercise: Create multiple counters&lt;br /&gt;Create multiple counters separated by newlines&lt;br /&gt;I run the script like this: counter.pl 3&lt;br /&gt;This will increment the counter #3 by one and print the value.&lt;br /&gt;13.9. Exercises: List old logfiles&lt;br /&gt;List all the logfiles in the current directory that are older than 3 days&lt;br /&gt;List all the log files in this directory and subdirectories that&lt;br /&gt;are more than 3 days old.&lt;br /&gt;13.10. Solution: Create a counter&lt;br /&gt;Example 13-4. examples/files/counter.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my $filename = "counter.txt";&lt;br /&gt;if (not -e $filename) {&lt;br /&gt;open my $fh, "&gt;", $filename or die "Could not create counter file: $!";&lt;br /&gt;print $fh 0;&lt;br /&gt;}&lt;br /&gt;open my $fh, "+&lt;", $filename or die "Could not open counter: $!\n";&lt;br /&gt;my $c = &lt;$fh&gt;;&lt;br /&gt;chomp $c;&lt;br /&gt;seek $fh, 0, 0;&lt;br /&gt;truncate $fh, 0;&lt;br /&gt;$c++;&lt;br /&gt;print $c;&lt;br /&gt;print $fh $c;&lt;br /&gt;close $fh;&lt;br /&gt; 104&lt;br /&gt;Chapter 13. More about files&lt;br /&gt;13.11. Solution: Create multiple counters&lt;br /&gt;Example 13-5. examples/files/multiple_counter.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;unless (@ARGV) {&lt;br /&gt;print "Usage: $0 &lt;counter-id&gt;\n";&lt;br /&gt;exit;&lt;br /&gt;}&lt;br /&gt;my $id = shift @ARGV;&lt;br /&gt;$id--; # because we index the counters from 1 and the array is from 0&lt;br /&gt;my $filename = "multiple_counter.txt";&lt;br /&gt;if (not -e $filename) {&lt;br /&gt;open my $fh, "&gt;", $filename or die "Could not create counter file: $!";&lt;br /&gt;print $fh 0;&lt;br /&gt;}&lt;br /&gt;open my $fh, "+&lt;", $filename or die "Could not open counter: $!\n";&lt;br /&gt;my @c = &lt;$fh&gt;;&lt;br /&gt;chomp @c;&lt;br /&gt;seek $fh, 0, 0; # move to the beginning of the file&lt;br /&gt;truncate $fh, 0; # cut the file to a certain size&lt;br /&gt;$c[$id]++;&lt;br /&gt;print $c[$id];&lt;br /&gt;foreach my $v (@c) {&lt;br /&gt;if (defined $v) {&lt;br /&gt;print $fh "$v\n";&lt;br /&gt;} else {&lt;br /&gt;print $fh "\n";&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;close $fh;&lt;br /&gt;13.12. Solutions: List old logfiles&lt;br /&gt;Example 13-6. examples/shell/logfiles_older_than3days.txt&lt;br /&gt;perl -e ’for (&lt;*.log&gt;) {print "$_\n" if -M $_ &gt; 3}’&lt;br /&gt; 105&lt;br /&gt;Chapter 13. More about files&lt;br /&gt;Example 13-7. examples/shell/list_old_log_files.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;use File::Find ’find’;&lt;br /&gt;find({&lt;br /&gt;wanted =&gt; \&amp;old_files,&lt;br /&gt;no_chdir =&gt; 1,&lt;br /&gt;}, $ARGV[0] || ’.’);&lt;br /&gt;sub old_files {&lt;br /&gt;if (substr($_, -4) ne ".log") {&lt;br /&gt;return;&lt;br /&gt;}&lt;br /&gt;if (-M $_ &gt; 3) {&lt;br /&gt;print "$_\n";&lt;br /&gt;}&lt;br /&gt;return;&lt;br /&gt;}&lt;br /&gt; 106&lt;br /&gt;Chapter 14. Using Perl modules, using CPAN&lt;br /&gt;14.1. Using modules exporting functions&lt;br /&gt;use Cwd;&lt;br /&gt;my $path = cwd;&lt;br /&gt;Probably better this way, so the reader will know where each function comes from and we reduce the risk&lt;br /&gt;of redefining other functions by importing exactly the functions we want.&lt;br /&gt;use Cwd (’cwd’);&lt;br /&gt;my $path = cwd;&lt;br /&gt;also written as&lt;br /&gt;use Cwd qw(cwd);&lt;br /&gt;my $path = cwd;&lt;br /&gt;You can also make sure not to import anything and the use fully qualified names.&lt;br /&gt;use Cwd ();&lt;br /&gt;my $path = Cwd::cwd;&lt;br /&gt;14.2. Using Object Oriented modules&lt;br /&gt;Example 14-1. examples/cpan/math_bigint.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;use Math::BigInt;&lt;br /&gt;my $x = Math::BigInt-&gt;new("1234567890");&lt;br /&gt;my $y = Math::BigInt-&gt;new("8234567890");&lt;br /&gt;$x-&gt;badd($y);&lt;br /&gt;print $x-&gt;bstr, "\n"; # 9469135780&lt;br /&gt;107&lt;br /&gt;Chapter 14. Using Perl modules, using CPAN&lt;br /&gt;14.3. Selecting Module to use&lt;br /&gt;Evaluating modules, getting information about them&lt;br /&gt;• CPAN http://www.cpan.org/&lt;br /&gt;• Searching CPAN http://search.cpan.org/&lt;br /&gt;• Randy Kobes CPAN http://kobesearch.cpan.org/&lt;br /&gt;• POD = Plain Old Documentation&lt;br /&gt;• CPAN Testers http://testers.cpan.org/&lt;br /&gt;• CPAN Ratings http://cpanratings.perl.org/&lt;br /&gt;• CPANTS http://cpants.perl.org/&lt;br /&gt;• RT (Request Tracker) http://rt.cpan.org/&lt;br /&gt;• Annotate POD http://annocpan.org/&lt;br /&gt;• CPAN::Forum http://www.cpanforum.com/&lt;br /&gt;• Mailing lists http://lists.cpan.org/&lt;br /&gt;• PerlMonks http://www.perlmonks.org/&lt;br /&gt;• Perl Mongers http://www.pm.org/&lt;br /&gt;• Perl Mongers in Israel http://www.perl.org.il/&lt;br /&gt;14.4. Installing modules on ActivePerl&lt;br /&gt;C:&gt; ppm&lt;br /&gt;ppm&gt; install Name-Of-Module&lt;br /&gt;in case it returns a list of modules, pick up the correct number:&lt;br /&gt;ppm&gt; install 3&lt;br /&gt;There are additional sites with ppm repositories once can find on Kobes Search&lt;br /&gt;Add the repository to ppm and install modules from that place as well:&lt;br /&gt;ppm&gt; rep add uwin http://theoryx5.uwinnipeg.ca/ppms/&lt;br /&gt;ppm&gt; install IO-Socket-SSL&lt;br /&gt;in ActiveState 5.6.x&lt;br /&gt;ppm&gt; set rep name URL&lt;br /&gt;In case the computer is behind a company proxy you can configure&lt;br /&gt; 108&lt;br /&gt;Chapter 14. Using Perl modules, using CPAN&lt;br /&gt;the http_proxy environment variable and ppm will use the proxy:&lt;br /&gt;set http_proxy=http://proxy.company.com:8080&lt;br /&gt;14.5. Installing modules on Unix manually with root&lt;br /&gt;rights&lt;br /&gt;• Download the tar.gz file from search.cpan or other site (wget URL)&lt;br /&gt;• Linux: tar xzf distribution.tar.gz&lt;br /&gt;• UNIX: gunzip distribution.tar.gz&lt;br /&gt;• UNIX: tar xf distribution.tar&lt;br /&gt;• perl Makefile.PL&lt;br /&gt;• make&lt;br /&gt;• make test&lt;br /&gt;• make install (as root)&lt;br /&gt;Without root rights&lt;br /&gt;perl Makefile.PL PREFIX=/home/foobar/perlib LIB=/home/foobar/perlib/lib&lt;br /&gt;In the code:&lt;br /&gt;use lib ’/home/foobar/perlib/lib’;&lt;br /&gt;use My::Module;&lt;br /&gt;Module::Build&lt;br /&gt;perl Build.PL --install_base /home/foobar/perl5lib --install_path lib=/home/foobar/perl5lib/lib&lt;br /&gt;./Build&lt;br /&gt;./Build test&lt;br /&gt;./Build install&lt;br /&gt;14.6. Changing @INC&lt;br /&gt;When using modules that are not installed in the standard directories&lt;br /&gt;and we cannot assume (or require) to run the script in the same directory&lt;br /&gt;where the module is. That is in most of the cases, we need to change @INC&lt;br /&gt;so our script can find our module(s).&lt;br /&gt;Set the environment variable&lt;br /&gt; 109&lt;br /&gt;Chapter 14. Using Perl modules, using CPAN&lt;br /&gt;PERL5LIB or PERLLIB for all the scripts&lt;br /&gt;use lib ’path/to/lib’; for the sepcific script&lt;br /&gt;perl -I path/to/lib script.pl for this invocation only&lt;br /&gt;# relative path&lt;br /&gt;use FindBin;&lt;br /&gt;use File::Spec;&lt;br /&gt;use lib File::Spec-&gt;catfile($FindBin::Bin, ’..’, ’lib’);&lt;br /&gt;# relative path&lt;br /&gt;use File::Spec;&lt;br /&gt;use File::Basename;&lt;br /&gt;use lib File::Spec-&gt;catfile(&lt;br /&gt;File::Basename::dirname(File::Spec-&gt;rel2abs($0)),&lt;br /&gt;’..’,&lt;br /&gt;’lib’);&lt;br /&gt;14.7. Using CPAN.pm&lt;br /&gt;$ cpan&lt;br /&gt;cpan&gt; install Module::Name&lt;br /&gt;Need to configure CPAN.pm:&lt;br /&gt;set urllist to a CPAN mirror that is close by&lt;br /&gt;set prerequisites_policy to follow&lt;br /&gt;set makepl_arg (PREFIX=... LIB=...)&lt;br /&gt;perl -MCPAN -eshell&lt;br /&gt;14.8. CPAN.pm&lt;br /&gt;Example 14-2. examples/cpan/ENV&lt;br /&gt;export PERL5LIB=/home/gabor/perl5lib/lib&lt;br /&gt;Example 14-3. examples/cpan/MyConfig.pm&lt;br /&gt;# This is CPAN.pm’s systemwide configuration file. This file provides&lt;br /&gt;# defaults for users, and the values can be changed in a per-user&lt;br /&gt;# configuration file. The user-config file is being looked for as&lt;br /&gt; 110&lt;br /&gt;Chapter 14. Using Perl modules, using CPAN&lt;br /&gt;# ~/.cpan/CPAN/MyConfig.pm.&lt;br /&gt;$CPAN::Config = {&lt;br /&gt;’build_cache’ =&gt; q[10],&lt;br /&gt;’build_dir’ =&gt; q[/home/gabor/.cpan/build],&lt;br /&gt;’cache_metadata’ =&gt; q[1],&lt;br /&gt;’cpan_home’ =&gt; q[/home/gabor/.cpan],&lt;br /&gt;’dontload_hash’ =&gt; { },&lt;br /&gt;’ftp’ =&gt; q[/usr/kerberos/bin/ftp],&lt;br /&gt;’ftp_proxy’ =&gt; q[],&lt;br /&gt;’getcwd’ =&gt; q[cwd],&lt;br /&gt;’gpg’ =&gt; q[/usr/bin/gpg],&lt;br /&gt;’gzip’ =&gt; q[/bin/gzip],&lt;br /&gt;’histfile’ =&gt; q[/home/gabor/.cpan/histfile],&lt;br /&gt;’histsize’ =&gt; q[100],&lt;br /&gt;’http_proxy’ =&gt; q[],&lt;br /&gt;’inactivity_timeout’ =&gt; q[0],&lt;br /&gt;’index_expire’ =&gt; q[1],&lt;br /&gt;’inhibit_startup_message’ =&gt; q[0],&lt;br /&gt;’keep_source_where’ =&gt; q[/home/gabor/.cpan/sources],&lt;br /&gt;’links’ =&gt; q[/usr/bin/links],&lt;br /&gt;’make’ =&gt; q[/usr/bin/make],&lt;br /&gt;’make_arg’ =&gt; q[],&lt;br /&gt;’make_install_arg’ =&gt; q[],&lt;br /&gt;’makepl_arg’ =&gt; q[PREFIX=/home/gabor/perl5lib LIB=/home/gabor/perl5lib/lib],&lt;br /&gt;’ncftpget’ =&gt; q[/usr/bin/ncftpget],&lt;br /&gt;’no_proxy’ =&gt; q[],&lt;br /&gt;’pager’ =&gt; q[/usr/bin/less],&lt;br /&gt;’prerequisites_policy’ =&gt; q[follow],&lt;br /&gt;’scan_cache’ =&gt; q[atstart],&lt;br /&gt;’shell’ =&gt; q[/bin/bash],&lt;br /&gt;’tar’ =&gt; q[/bin/tar],&lt;br /&gt;’term_is_latin’ =&gt; q[1],&lt;br /&gt;’unzip’ =&gt; q[/usr/bin/unzip],&lt;br /&gt;’urllist’ =&gt; [q[http://mirror.mirimar.net/cpan/]],&lt;br /&gt;’wget’ =&gt; q[/usr/bin/wget],&lt;br /&gt;};&lt;br /&gt;1;&lt;br /&gt;__END__&lt;br /&gt;14.9. CPANPLUS, CPAN::Reporter&lt;br /&gt;cpan&gt; install CPAN::Reporter&lt;br /&gt;cpan&gt; reload cpan&lt;br /&gt;cpan&gt; o conf init test_report&lt;br /&gt;cpan&gt; o conf commit&lt;br /&gt; 111&lt;br /&gt;Chapter 14. Using Perl modules, using CPAN&lt;br /&gt;14.10. Exercise: Module installation&lt;br /&gt;Install the Acme::EyeDrops module from CPAN and write a script&lt;br /&gt;to draw a camel. As you are not root, you might need to install it in&lt;br /&gt;a local subdirectory.&lt;br /&gt;Create a simple script that does some simple computation.&lt;br /&gt;Creata a script using Acme::EyeDrops that will use the above simple script as&lt;br /&gt;source.&lt;br /&gt;Save your camel in a file.&lt;br /&gt;Run the file containing the camel using Perl.&lt;br /&gt;14.11. Solution: Module installation&lt;br /&gt;Example 14-4. examples/cpan/acme_camel.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;=pod&lt;br /&gt;search.cpan.org&lt;br /&gt;search Acme::EyeDrops&lt;br /&gt;download the latest Acme-EyeDrops gziped file (for me it was Acme-EyeDrops-1.01.tar.gz)&lt;br /&gt;mkdir modules (create a local directory where we’ll install the module)&lt;br /&gt;tar xzf Acme-EyeDrops-1.01.tar.gz&lt;br /&gt;cd Acme-EyeDrops-1.01&lt;br /&gt;perl Makefile.PL PREFIX=/home/user/modules LIB=/home/user/module/lib&lt;br /&gt;(the full path to the directory you created for the modules)&lt;br /&gt;make&lt;br /&gt;make test&lt;br /&gt;make install&lt;br /&gt;Create a script called hello_world.pl that asks for your name and then&lt;br /&gt;prints Hello NAME.&lt;br /&gt;Run this script. See the camel.&lt;br /&gt;Now run this script and redirect to another file&lt;br /&gt;perl acme_camel.pl &gt; camel.pl&lt;br /&gt;Now run the camel:&lt;br /&gt;perl camel.pl&lt;br /&gt;=cut&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt; 112&lt;br /&gt;Chapter 14. Using Perl modules, using CPAN&lt;br /&gt;use lib qw (/home/user/modules/lib/);&lt;br /&gt;use Acme::EyeDrops qw (sightly);&lt;br /&gt;print sightly({&lt;br /&gt;Shape =&gt; ’camel’,&lt;br /&gt;SourceFile =&gt; ’hello_world.pl’,&lt;br /&gt;});&lt;br /&gt; 113&lt;br /&gt;Chapter 15. Applications&lt;br /&gt;15.1. Simple uses of Perl&lt;br /&gt;After leaning the syntax of the language let’s see a few simple ways to use it in real life tasks.&lt;br /&gt;15.2. Create Unix user account&lt;br /&gt;Example 15-1. examples/applications/create_user.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;my $adduser = ’/usr/sbin/adduser’;&lt;br /&gt;use Getopt::Long qw(GetOptions);&lt;br /&gt;my %opts;&lt;br /&gt;GetOptions(\%opts,&lt;br /&gt;’fname=s’,&lt;br /&gt;’lname=s’,&lt;br /&gt;) or usage();&lt;br /&gt;if (not $opts{fname} or $opts{fname} !~ /^[a-zA-Z]+$/) {&lt;br /&gt;usage("First name must be alphabetic");&lt;br /&gt;}&lt;br /&gt;if (not $opts{lname} or $opts{lname} !~ /^[a-zA-Z]+$/) {&lt;br /&gt;usage("Last name must be alphabetic");&lt;br /&gt;}&lt;br /&gt;my $username = lc( substr($opts{lname}, 0, 1) . $opts{fname});&lt;br /&gt;my $home = "/opt/$username";&lt;br /&gt;print "Username: $username\n";&lt;br /&gt;my $cmd = qq($adduser --home $home --disabled-password --gecos "$opts{fname} $opts{lname}" $print "$cmd\n";&lt;br /&gt;system $cmd;&lt;br /&gt;sub usage {&lt;br /&gt;my ($msg) = @_;&lt;br /&gt;if ($msg) {&lt;br /&gt;print "$msg\n\n";&lt;br /&gt;114&lt;br /&gt;Chapter 15. Applications&lt;br /&gt;}&lt;br /&gt;print "Usage: $0 --fname FirstName --lname LastName\n";&lt;br /&gt;exit;&lt;br /&gt;}&lt;br /&gt;15.3. Reporting file system diskspace usage (df)&lt;br /&gt;Example 15-2. examples/applications/diskspace.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;use Filesys::Df qw(df);&lt;br /&gt;my $df = df("/", 1024 * 1024 * 1024);&lt;br /&gt;print "Percent Full: $df-&gt;{per}\n";&lt;br /&gt;print "Superuser Blocks: $df-&gt;{blocks}\n";&lt;br /&gt;print "Superuser Blocks Available: $df-&gt;{bfree}\n";&lt;br /&gt;print "User Blocks: $df-&gt;{user_blocks}\n";&lt;br /&gt;print "User Blocks Available: $df-&gt;{bavail}\n";&lt;br /&gt;print "Blocks Used: $df-&gt;{used}\n";&lt;br /&gt;15.4. Reporting diskspace usage on the mail server&lt;br /&gt;Example 15-3. examples/applications/diskusage.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;#&lt;br /&gt;# Reporting disk usage on the mail server&lt;br /&gt;#&lt;br /&gt;# Run the script in a cron job&lt;br /&gt;#&lt;br /&gt;# 1) Report to Boss if there are people with large files&lt;br /&gt;#&lt;br /&gt;# 2) If a user has a file that is too big then ask him to remove the&lt;br /&gt;# large e-mail from the mail server via web access&lt;br /&gt;# This one has not been implemented yet&lt;br /&gt;#&lt;br /&gt;######################################################&lt;br /&gt;use Mail::Sendmail qw(sendmail);&lt;br /&gt;use Filesys::Df qw(df);&lt;br /&gt; 115&lt;br /&gt;Chapter 15. Applications&lt;br /&gt;################## Limit Definitions&lt;br /&gt;my $report_to_boss_limit = 1_000_000; # the size of the /var/spool/mail/username file in my $report_to_user_limit = 1_000_000;&lt;br /&gt;my $boss_email = ’boss@company’;&lt;br /&gt;my $from_email = ’Disk Usage Report &lt;sysadmin@company&gt;’;&lt;br /&gt;my $disk_space_percantage = 80;&lt;br /&gt;my %file_size;&lt;br /&gt;foreach my $path (&lt;/var/spool/mail/*&gt;) { # each user has a file in that directory&lt;br /&gt;if ($path =~ /Save/) { # disregard the Save directory&lt;br /&gt;next;&lt;br /&gt;}&lt;br /&gt;if ($path =~ /\.pop$/) { # disregard temporary .pop files&lt;br /&gt;next;&lt;br /&gt;}&lt;br /&gt;$file_size{$path} = -s $path;&lt;br /&gt;}&lt;br /&gt;my $txt = "x";&lt;br /&gt;# sort files by size&lt;br /&gt;foreach my $path (sort {$file_size{$b} &lt;=&gt; $file_size{$a}} keys %file_size) {&lt;br /&gt;my $name = $path;&lt;br /&gt;$name =~ s{/var/spool/mail/}{};&lt;br /&gt;if ($file_size{$path} &gt; $report_to_boss_limit) {&lt;br /&gt;$txt .= "$name\t\t" . int ($file_size{$_}/1_000_000) . " MB\n";&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;my @disks = qw(/ /boot);&lt;br /&gt;foreach my $disk (@disks) {&lt;br /&gt;my $df = df($disk, 1024 * 1024 * 1024);&lt;br /&gt;if ($df-&gt;{per} &gt; $disk_space_percantage) {&lt;br /&gt;$txt .= "\n\nDiskspace is low\n\nUsing " . $df-&gt;{per} . "\% of the space on $disk\n";&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;if ($txt) {&lt;br /&gt;$txt = "Disk Usage of /var/spool/mail on the incoming mail server\n" .&lt;br /&gt;"Reporting users over $report_to_boss_limit bytes\n\n" .&lt;br /&gt;$txt;&lt;br /&gt;sendmail (&lt;br /&gt;To =&gt; $boss_email,&lt;br /&gt;From =&gt; $from_email,&lt;br /&gt;Subject =&gt; ’Disk Usage Report’ . localtime(),&lt;br /&gt;Message =&gt; $txt,&lt;br /&gt;);&lt;br /&gt;}&lt;br /&gt; 116&lt;br /&gt;Chapter 15. Applications&lt;br /&gt;15.5. A du like script&lt;br /&gt;Example 15-4. examples/applications/du.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;use Filesys::DiskUsage qw(du);&lt;br /&gt;my %sizes = du({’make-hash’ =&gt; 1}, @ARGV);&lt;br /&gt;foreach my $entry (sort { $sizes{$a} &lt;=&gt; $sizes{$b} } keys %sizes) {&lt;br /&gt;print "$entry =&gt; $sizes{$entry}\n";&lt;br /&gt;}&lt;br /&gt;15.6. Send e-mail&lt;br /&gt;• Mail::Sendmail&lt;br /&gt;Example 15-5. examples/applications/sendmail.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;use Getopt::Long "GetOptions";&lt;br /&gt;use Mail::Sendmail "sendmail";&lt;br /&gt;my $to;&lt;br /&gt;my $from;&lt;br /&gt;my $help;&lt;br /&gt;my $file;&lt;br /&gt;GetOptions(&lt;br /&gt;"to=s" =&gt; \$to,&lt;br /&gt;"from=s" =&gt; \$from,&lt;br /&gt;"help" =&gt; \$help,&lt;br /&gt;"file=s" =&gt; \$file,&lt;br /&gt;);&lt;br /&gt;if ($help) {&lt;br /&gt;usage();&lt;br /&gt;}&lt;br /&gt;if ($to and $from and $file) {&lt;br /&gt;my ($subject, $message) = read_file($file);&lt;br /&gt;my %mail = (&lt;br /&gt;To =&gt; $to,&lt;br /&gt;From =&gt; $from,&lt;br /&gt;Subject =&gt; $subject,&lt;br /&gt;Message =&gt; $message,&lt;br /&gt; 117&lt;br /&gt;Chapter 15. Applications&lt;br /&gt;);&lt;br /&gt;sendmail(%mail) or die $Mail::Sendmail::error;&lt;br /&gt;} else {&lt;br /&gt;usage();&lt;br /&gt;}&lt;br /&gt;sub usage {&lt;br /&gt;print "Usage: $0\n";&lt;br /&gt;print " --to TO\n";&lt;br /&gt;print " --from FROM\n";&lt;br /&gt;print " --file FILE\n";&lt;br /&gt;print "\n";&lt;br /&gt;print " --help\n";&lt;br /&gt;print "\n";&lt;br /&gt;print "The given FILE is going to be the content of the e-mail\n";&lt;br /&gt;print "The first line of the file should be:\n";&lt;br /&gt;print "Subject: and the subject itself\n";&lt;br /&gt;print "\n";&lt;br /&gt;exit;&lt;br /&gt;}&lt;br /&gt;sub read_file {&lt;br /&gt;my ($file) = @_;&lt;br /&gt;open(my $fh, "&lt;", $file) or die "Could not open ’$file’\n";&lt;br /&gt;my $subject = &lt;$fh&gt;;&lt;br /&gt;local $/ = undef;&lt;br /&gt;my $message = &lt;$fh&gt;;&lt;br /&gt;$subject =~ s/^Subject: //;&lt;br /&gt;return ($subject, $message);&lt;br /&gt;}&lt;br /&gt;15.7. Read Excel file&lt;br /&gt;Example 15-6. examples/applications/read_excel.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;use Spreadsheet::ParseExcel::Simple qw();&lt;br /&gt;my $xls = Spreadsheet::ParseExcel::Simple-&gt;read("spreadsheet.xls");&lt;br /&gt;foreach my $sheet ($xls-&gt;sheets) {&lt;br /&gt;while ($sheet-&gt;has_data) {&lt;br /&gt; 118&lt;br /&gt;Chapter 15. Applications&lt;br /&gt;my @data = $sheet-&gt;next_row;&lt;br /&gt;print join "|", @data;&lt;br /&gt;print "\n";&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;15.8. Process file with fixed width records&lt;br /&gt;Example 15-7. examples/applications/pack.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;# You need to parse a log file where the fields are fixed length long&lt;br /&gt;# and have no delimiters&lt;br /&gt;# The definition is as follows:&lt;br /&gt;# LABEL: 4 chars&lt;br /&gt;# SOURCE: 8 digits&lt;br /&gt;# DESTINATION: 8 digits&lt;br /&gt;# TYPE: 4 chars&lt;br /&gt;# VALUE: 8 digits&lt;br /&gt;my $file = ’examples/pack.txt’;&lt;br /&gt;open(my $data, ’&lt;’, $file) or die "Could not open ’$file’\n";&lt;br /&gt;while (my $line = &lt;$data&gt;) {&lt;br /&gt;print $line;&lt;br /&gt;chomp $line;&lt;br /&gt;my ($label, $source, $dest, $type, $value) = unpack ("A4 A8 A8 A4 A8", $line);&lt;br /&gt;print "LABEL: $label SOURCE: $source DEST: $dest TYPE: $type VALUE: $value\n";&lt;br /&gt;}&lt;br /&gt;Example 15-8. examples/applications/pack.txt&lt;br /&gt;ALD37845566974923342XYZ24023984&lt;br /&gt;QRW49327408234028434ERD24448009&lt;br /&gt;15.9. Process file with multiline records&lt;br /&gt;Example 15-9. examples/applications/config.txt&lt;br /&gt;device = 234234&lt;br /&gt;name = Big&lt;br /&gt;address = 115.6.79.8&lt;br /&gt;class = B&lt;br /&gt;device = 234224&lt;br /&gt; 119&lt;br /&gt;Chapter 15. Applications&lt;br /&gt;name = Big Blue&lt;br /&gt;address = 115.6.69.8&lt;br /&gt;class = B&lt;br /&gt;alias = Foxbox&lt;br /&gt;device = 234235&lt;br /&gt;name = Big Green box&lt;br /&gt;address = 115.6.79.1&lt;br /&gt;class = G&lt;br /&gt;owner = Boss&lt;br /&gt;device = 334235&lt;br /&gt;name = Small Yellow&lt;br /&gt;address = 115.6.79.10&lt;br /&gt;class = Y&lt;br /&gt;Example 15-10. examples/applications/process_config.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;=head1 DESCRIPTION&lt;br /&gt;File have sections separated by empty lines&lt;br /&gt;Each section has several field = value entries like this:&lt;br /&gt;Given a value of the name field print out all the values in this section&lt;br /&gt;device = 234234&lt;br /&gt;name = Big&lt;br /&gt;address = 115.6.79.8&lt;br /&gt;class = B&lt;br /&gt;=cut&lt;br /&gt;if (@ARGV != 2) {&lt;br /&gt;die "\n Usage: $0 filename name\n Try: $0 examples/config.txt Big\n\n";&lt;br /&gt;}&lt;br /&gt;my ($filename, $name) = @ARGV;&lt;br /&gt;open(my $fh, "&lt;", $filename) or die "Could not open ’$filename’ $!";&lt;br /&gt;my %data;&lt;br /&gt;while (my $line = &lt;$fh&gt;) {&lt;br /&gt;chomp $line;&lt;br /&gt;if ($line =~ /^\s*$/ and %data) {&lt;br /&gt;if ($data{name} eq $name) {&lt;br /&gt;foreach my $k (keys %data) {&lt;br /&gt;printf "%-10s = %s\n", $k, $data{$k};&lt;br /&gt;}&lt;br /&gt;exit;&lt;br /&gt;}&lt;br /&gt;%data = ();&lt;br /&gt; 120&lt;br /&gt;Chapter 15. Applications&lt;br /&gt;} else {&lt;br /&gt;my ($field, $value) = split /\s*=\s*/, $line;&lt;br /&gt;$data{$field} = $value;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;15.10. Process multi field csv file&lt;br /&gt;Example 15-11. examples/applications/fields.csv&lt;br /&gt;Name,ID,Input,Output&lt;br /&gt;Big Venta,12,Left,Right&lt;br /&gt;Small Elevator,7343124,Bottom,Top&lt;br /&gt;Giant Ant,423235,Lower floor,Upper floor&lt;br /&gt;Example 15-12. examples/applications/process_fields.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;use Text::CSV_XS qw();&lt;br /&gt;use Data::Dumper qw(Dumper);&lt;br /&gt;my $filename = shift or die "Usage: $0 FILENAME\n";&lt;br /&gt;open(my $fh, "&lt;", $filename) or die "Could not open ’$filename’: $!";&lt;br /&gt;my $csv = Text::CSV_XS-&gt;new;&lt;br /&gt;my $key = "Name";&lt;br /&gt;my $header = &lt;$fh&gt;;&lt;br /&gt;chomp $header;&lt;br /&gt;$csv-&gt;parse($header);&lt;br /&gt;my @header = $csv-&gt;fields;&lt;br /&gt;my %data;&lt;br /&gt;while (my $line = &lt;$fh&gt;) {&lt;br /&gt;chomp $line;&lt;br /&gt;$csv-&gt;parse($line);&lt;br /&gt;my @cols = $csv-&gt;fields;&lt;br /&gt;my %h;&lt;br /&gt;@h{@header} = @cols;&lt;br /&gt;$data{$h{$key}} = \%h;&lt;br /&gt;}&lt;br /&gt;print Dumper \%data;&lt;br /&gt; 121&lt;br /&gt;Chapter 15. Applications&lt;br /&gt;15.11. Fetch web page&lt;br /&gt;Example 15-13. examples/applications/get_webpage.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;use LWP::Simple qw(get);&lt;br /&gt;my $page = get "http://web_development:8080/";&lt;br /&gt;if ($page) {&lt;br /&gt;print "Site is alive\n";&lt;br /&gt;} else {&lt;br /&gt;print "Site is not accessible\n";&lt;br /&gt;}&lt;br /&gt;15.12. Generate web page&lt;br /&gt;We are building the HTML pages from a template utilizing the HTML::Template module from CPAN.&lt;br /&gt;Besides the plain HTML the template has additional TMPL_* tags that will be filled by the values by&lt;br /&gt;HTML::Template.&lt;br /&gt;Example 15-14. examples/applications/html.tmpl&lt;br /&gt;&lt;html&gt;&lt;br /&gt;&lt;head&gt;&lt;br /&gt;&lt;/head&gt;&lt;br /&gt;&lt;body&gt;&lt;br /&gt;&lt;TMPL_IF echo&gt;&lt;br /&gt;You typed &lt;TMPL_VAR echo&gt;&lt;br /&gt;&lt;/TMPL_IF&gt;&lt;br /&gt;&lt;form&gt;&lt;br /&gt;&lt;input name="text"&gt;&lt;br /&gt;&lt;input type=submit" value="Echo"&gt;&lt;br /&gt;&lt;/form&gt;&lt;br /&gt;&lt;/body&gt;&lt;br /&gt;&lt;/html&gt;&lt;br /&gt; 122&lt;br /&gt;Chapter 15. Applications&lt;br /&gt;This is a simple Perl script that should be installed to a CGIExec enabled directory of Apache. When the&lt;br /&gt;user hits this page the first time it displays a white page with only entry-box and a submit button on it.&lt;br /&gt;the user can fill the box,&lt;br /&gt;Example 15-15. examples/applications/html.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;use CGI;&lt;br /&gt;use HTML::Template;&lt;br /&gt;my $template = HTML::Template-&gt;new(filename =&gt; "examples/html.tmpl");&lt;br /&gt;my $q = CGI-&gt;new;&lt;br /&gt;print $q-&gt;header;&lt;br /&gt;if ($q-&gt;param("text")) {&lt;br /&gt;my $text = $q-&gt;param("text");&lt;br /&gt;$template-&gt;param(echo =&gt; $text);&lt;br /&gt;}&lt;br /&gt;print $template-&gt;output&lt;br /&gt;15.13. Parse XML file&lt;br /&gt;Example 15-16. examples/applications/simple.xml&lt;br /&gt;&lt;people&gt;&lt;br /&gt;&lt;person id="1"&gt;&lt;br /&gt;&lt;fname&gt;Josef&lt;/fname&gt;&lt;br /&gt;&lt;lname&gt;Kiss&lt;/lname&gt;&lt;br /&gt;&lt;idnum&gt;4342324234&lt;/idnum&gt;&lt;br /&gt;&lt;children&gt;&lt;br /&gt;&lt;child&gt;&lt;br /&gt;&lt;id&gt;3&lt;/id&gt;&lt;br /&gt;&lt;/child&gt;&lt;br /&gt;&lt;/children&gt;&lt;br /&gt;&lt;/person&gt;&lt;br /&gt;&lt;person id="2"&gt;&lt;br /&gt;&lt;fname&gt;Peter&lt;/fname&gt;&lt;br /&gt;&lt;lname&gt;Kiss&lt;/lname&gt;&lt;br /&gt;&lt;idnum&gt;8768996&lt;/idnum&gt;&lt;br /&gt;&lt;/person&gt;&lt;br /&gt;&lt;person id="3"&gt;&lt;br /&gt;&lt;fname&gt;Zoltan&lt;/fname&gt;&lt;br /&gt;&lt;lname&gt;Kiss&lt;/lname&gt;&lt;br /&gt;&lt;idnum&gt;09808760&lt;/idnum&gt;&lt;br /&gt;&lt;/person&gt;&lt;br /&gt;&lt;/people&gt;&lt;br /&gt; 123&lt;br /&gt;Chapter 15. Applications&lt;br /&gt;Example 15-17. examples/applications/xml_simple.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;use XML::Simple qw(XMLin);&lt;br /&gt;my $xml = XMLin("examples/simple.xml", ForceArray =&gt; 1);&lt;br /&gt;#use Data::Dumper qw(Dumper);&lt;br /&gt;#print Dumper $xml;&lt;br /&gt;#exit;&lt;br /&gt;print join "-", keys %{$xml-&gt;{person}};&lt;br /&gt;print "\n";&lt;br /&gt;foreach my $id (keys %{$xml-&gt;{person}}) {&lt;br /&gt;printf "%-10s %-10s %-10s\n",&lt;br /&gt;$xml-&gt;{person}{$id}{fname}[0],&lt;br /&gt;$xml-&gt;{person}{$id}{lname}[0],&lt;br /&gt;$xml-&gt;{person}{$id}{idnum}[0];&lt;br /&gt;}&lt;br /&gt;15.14. Database access using DBI and DBD::SQLite&lt;br /&gt;Example 15-18. examples/applications/db.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;use Getopt::Long qw(GetOptions);&lt;br /&gt;use DBI qw();&lt;br /&gt;my $action;&lt;br /&gt;GetOptions("action=s" =&gt; \$action);&lt;br /&gt;if (not $action or $action !~ /^(create|insert|selecta|selecth)$/) {&lt;br /&gt;print &lt;&lt;"USAGE";&lt;br /&gt;Usage:&lt;br /&gt;$0 --action create|insert|selecta|selecth&lt;br /&gt;USAGE&lt;br /&gt;exit;&lt;br /&gt;}&lt;br /&gt;my $dbfile = "sample.db";&lt;br /&gt;if ($action eq "create") {&lt;br /&gt;create();&lt;br /&gt;exit;&lt;br /&gt;}&lt;br /&gt; 124&lt;br /&gt;Chapter 15. Applications&lt;br /&gt;my $dbh = DBI-&gt;connect("dbi:SQLite:dbname=$dbfile","","", {});&lt;br /&gt;if ($action eq "insert") {&lt;br /&gt;insert();&lt;br /&gt;}&lt;br /&gt;if ($action eq "selecta") {&lt;br /&gt;fetch_arrays();&lt;br /&gt;}&lt;br /&gt;if ($action eq "selecth") {&lt;br /&gt;fetch_hashref();&lt;br /&gt;}&lt;br /&gt;sub create {&lt;br /&gt;unlink $dbfile if -e $dbfile;&lt;br /&gt;my $dbh = DBI-&gt;connect("dbi:SQLite:dbname=$dbfile","","", {});&lt;br /&gt;$dbh-&gt;do("CREATE TABLE people (id INTEGER PRIMARY KEY, fname VARCHAR(100), lname VARCHAR(return;&lt;br /&gt;}&lt;br /&gt;sub insert {&lt;br /&gt;$dbh-&gt;do("INSERT INTO people (id, fname, lname) VALUES(?, ?, ?)", undef, 1, "Gabor", "Szabo");&lt;br /&gt;$dbh-&gt;do("INSERT INTO people (id, fname, lname) VALUES(?, ?, ?)", undef, 2, "Josef", "Kiss");&lt;br /&gt;return;&lt;br /&gt;}&lt;br /&gt;sub fetch_arrays {&lt;br /&gt;my $sth = $dbh-&gt;prepare("SELECT lname, fname FROM people WHERE id = ?");&lt;br /&gt;$sth-&gt;execute(1);&lt;br /&gt;while (my @result = $sth-&gt;fetchrow_array()) {&lt;br /&gt;print "lname: $result[0], fname: $result[1]\n";&lt;br /&gt;}&lt;br /&gt;$sth-&gt;finish;&lt;br /&gt;return;&lt;br /&gt;}&lt;br /&gt;sub fetch_hashref {&lt;br /&gt;my $sth = $dbh-&gt;prepare("SELECT lname, fname FROM people WHERE id = ?");&lt;br /&gt;$sth-&gt;execute(1);&lt;br /&gt;while (my $result = $sth-&gt;fetchrow_hashref("NAME_lc")) {&lt;br /&gt;print "lname: $result-&gt;{lname}, fname: $result-&gt;{fname}\n";&lt;br /&gt;}&lt;br /&gt;$sth-&gt;finish;&lt;br /&gt;return;&lt;br /&gt;}&lt;br /&gt; 125&lt;br /&gt;Chapter 15. Applications&lt;br /&gt;15.15. Net::LDAP&lt;br /&gt;Example 15-19. examples/applications/ldap.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;use Net::LDAP;&lt;br /&gt;my $server = "ldap.itd.umich.edu";&lt;br /&gt;my $ldap = Net::LDAP-&gt;new( $server ) or die "$@";&lt;br /&gt;$ldap-&gt;bind;&lt;br /&gt;my $result = $ldap-&gt;search(&lt;br /&gt;base =&gt; "",&lt;br /&gt;filter =&gt; "(&amp;(cn=Ver*) (sn=Szab*))",&lt;br /&gt;attr =&gt; ["mail"],&lt;br /&gt;);&lt;br /&gt;$result-&gt;code &amp;&amp; die $result-&gt;error;&lt;br /&gt;printf "COUNT: %s\n", $result-&gt;count;&lt;br /&gt;foreach my $entry ($result-&gt;entries) {&lt;br /&gt;$entry-&gt;dump;&lt;br /&gt;}&lt;br /&gt;print "===============================================\n";&lt;br /&gt;foreach my $entry ($result-&gt;entries) {&lt;br /&gt;printf "%s &lt;%s&gt;\n", $entry-&gt;get_value("displayName"), $entry-&gt;get_value("mail");&lt;br /&gt;$entry-&gt;add ( "brother" =&gt; "Gabor" );&lt;br /&gt;$entry-&gt;replace ( "mail" =&gt; ’verele@verele.com’);&lt;br /&gt;my $res = $entry-&gt;update($ldap);&lt;br /&gt;$res-&gt;code &amp;&amp; die $res-&gt;code;&lt;br /&gt;}&lt;br /&gt;$ldap-&gt;add(&lt;br /&gt;’cn=root, o=University of Michigan, c=US’,&lt;br /&gt;attr =&gt; [&lt;br /&gt;cn =&gt; ’Gabor Szabo’,&lt;br /&gt;ou =&gt; ’My Place in the Universe’,&lt;br /&gt;mail =&gt; ’gabor@pti.co.il’,&lt;br /&gt;],&lt;br /&gt;);&lt;br /&gt;$ldap-&gt;unbind;&lt;br /&gt; 126&lt;br /&gt;Chapter 15. Applications&lt;br /&gt;15.16. Tie::File&lt;br /&gt;Example 15-20. examples/applications/tie.pl&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;use Tie::File;&lt;br /&gt;tie my @file, ’Tie::File’, "data.txt" or die $!;&lt;br /&gt;$file[7] = "Hello";&lt;br /&gt; 127&lt;br /&gt;Chapter 16. Oneliners&lt;br /&gt;16.1. Change encoding in a file&lt;br /&gt;perl -i.bak -MEncode -p -e ’Encode::from_to($_, "iso-8859-2", "utf8")’ html/download/printable_cv.html&lt;br /&gt;16.2. Replace file content&lt;br /&gt;You have a bunch of text files in your directory mentioning the name:&lt;br /&gt;"Microsoft Word"&lt;br /&gt;You are told to replace that by&lt;br /&gt;"OpenOffice Write"&lt;br /&gt;perl -i -p -e "s/MicrosoftWord/OpenOffice Write/g" *.txt&lt;br /&gt;-i = inplace editing&lt;br /&gt;-p = loop over lines and print each line (after processing)&lt;br /&gt;-e = command line script&lt;br /&gt;16.3. Process a csv file&lt;br /&gt;You have a number of csv files,&lt;br /&gt;you want to print the 3rd field of each row of each file.&lt;br /&gt;perl -a -F, -n -e ’print "$F[2]\n"’ *.csv&lt;br /&gt;-n = loop over lines but do NOT print them&lt;br /&gt;-a = autosplit by ’ ’&lt;br /&gt;-F, = replace the split string by ’,’&lt;br /&gt;In a CSV file you would like to sum up the numbers in the 3rd column.&lt;br /&gt;perl -a -F, -n -e ’$sum += $F[2]; END {print $sum}’ examples/arrays/process_csv_file.csv&lt;br /&gt;The END block gets executed at the end of the execution and only once.&lt;br /&gt;You want to make sure all the rows are 4 elements long.&lt;br /&gt;128&lt;br /&gt;Chapter 16. Oneliners&lt;br /&gt;Print out file name and line number of all the bad rows.&lt;br /&gt;perl -a -F, -n -e ’print "$ARGV:$.\n" if @F != 4’ *.csv&lt;br /&gt;See also perldoc perlrun&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2938427049868690639-4123172337581472321?l=scriptingfaqs.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://scriptingfaqs.blogspot.com/feeds/4123172337581472321/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2938427049868690639&amp;postID=4123172337581472321' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2938427049868690639/posts/default/4123172337581472321'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2938427049868690639/posts/default/4123172337581472321'/><link rel='alternate' type='text/html' href='http://scriptingfaqs.blogspot.com/2008/07/perl-script-notes.html' title='Perl Script notes'/><author><name>Siebel Expert</name><uri>http://www.blogger.com/profile/11533458660230230361</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
