Perl Search for Files and Directories Perl Remove Directory Perl Extract File and Directory Names from Full Paths Perl Copy File Perl Command Line Options Perl Environment Variables Perl Check File Exists Perl Get User Input Perl Upper Case Perl String Comparison Perl Exit Error Perl Get Number of Lines of an Array Perl Change
The following Perl code reads and replace some text in a file. Two code snippets are provided to read a small file and a large file: Reading a Small File Reading a Large File
Problem Write a regular expression in Perl to validate dates in the following format “mm/dd/yyyy”. The month and day fields can be one or two digits. Code Here is a sample Perl code to do that
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 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 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
Problem Given the following sequence of integer numbers: Write a recursive function that receives the index of a given number in the sequence above and returns the corresponding sequence number for example if index = 2 the function should return 2, if the index = 5 the function should return 8 and so on Solution