Question In Perl what is the difference between return and return undef Answer Using “return” alone returns an empty list in list context and undef in scalar context. On the other hand “return undef” always returns undef even in list context. Generally speaking it is not a good idea to return undef from a subroutine
Problem Provide example code in Perl to implement an array of C like structs Solution Use a hash table. The hash key is recommended to be a unique identifier and the hash value is a reference to an array. The idea is simple and the rest is just using the correct Perl syntax Code Here
Problem Write a Java method to replace a sub string in a given text with another string of the same size Solution Loop through the text character by character. Starting at the current character loop a number of times equal to the size of the sub string while comparing characters in the original text and the sub
Problem Write a C++ function to copy an existing string. Do not use built in functions. Solution This is a straight forward question and to my surprise I was asked this question in a site interview. If you are not prepared you might stumble on the easy ones. The idea is to allocate memory for
Problem You have a log file on UNIX operating system. Each line in the log file contains an IP address in the 10th column where columns (or fields) are separated by a space. How can you print the unique IP addresses in the log file using UNIX shell Solution This is the same problem as
Problem You have a log file on UNIX operating system. Each line in the log file contains an IP address in the 10th column where columns (or fields) are separated by a space. Write a Perl program to parse the log file and print the unique IP addresses in the log file Solution Read the
Problem Given a one dimensional integer array of 9 elements. Write a function to map the array into a row major 3×3 two dimensional array Solution If you are familiar with 3D graphics API like DirectX or OpenGL they store 4×4 transformation matrices as a linear array of 16 elements. In DirectX the format is
Question In C++ what is the difference between copy constructor and assignment operator. If they are created for you by default then why do we need to create them in the first place. Assignment operator vs copy constructor Copy constructors and assignment operators are created by default even if you do not implement your own.
Problem Given an array of n-1 unique integers. Each element in the array is an integer between 1 and n. Write a program to print the missing number in the array Solution To clarify this problem let us take a simple example. Assume n = 3 so the array consists from two elements only. Here
Problem Write a program to reverse an English sentence word by word not character by character. For example if the sentence is “I love Pizza so much” the program should print “much so Pizza love I” Solution One solution is to split the sentence into tokens using the space character as the separator then print