Chủ Nhật, 6 tháng 6, 2010

Bài tập Perl

Bài tập thực hành - Dùng trong môn perl programing Aiti-aptech

Perl Exercises

  1. Create and run a Perl program that prints "Hello, World" on the monitor.

  2. Write a program that prints the decimal number 32. However, in the print command, specify the value of 32 using hexadecimal notation.

  3. Create program that uses the tab character in three literals to align text.

  4. Write a program that prints using embedded new lines in a single-quoted literal.

  5. Convert the number 56,500,000 into scientific notation.

  6. Write a program that prints an array that uses the range operator. The left value should be AA and the right value should be BB. What happens and why?

  7. Write a program that prints its own source code

  8. Create a array called @months. It should have 12 elements in it with the names of the month represented as strings.

  9. Create a string that interpolates that value of the variable $numberOfBooks.

  10. Using the range operator (..) create an array with the following elements: 1, 5, 6, 7, 10, 11, 12.

  11. Using the array created in the last exercise, create a print command to display the last element.

  12. Create an associative array that holds a list of five music artists and a rating for them. Use "good," "bad," and "indifferent" as the ratings.

  13. Using the array created in the last exercise, create a print command to display the last element.

  14. Assign a value to $firstVar using both division and subtraction.

  15. Using the post-decrement operator, subtract one from $firstVar.

  16. Write a program that assigns values to $firstVar and $secondVar and uses the >= operator to test their relationship to each other. Print the resulting value.

  17. Use the **= assignment operator to assign a value to $firstVar.

  18. Use the ternary operator to decide between to different value.

  19. Write a program that assigns values to $firstVar and $secondVar and uses the <=> operator to test their relationship to each other. Print the resulting value.

  20. Use the concatenation operator to join the following values together: "A" x 4 and "B" x 3.

  21. Use the exponentiation operator to find the value of 2 to the 5th power.

  22. Write an assignment statement that uses the && and || and ! operators.

  23. Write a program that prints the value of the fifth bit from the right in a scalar variable.

  24. Write a program that uses a bitwise assignment to set the fifth bit from the right in a scalar variable.

  25. Write a program that shows the difference in operator precedence between the % operator and the && operator.

  26. Create a function that prints its own parameter list.

  27. Create a program that uses three functions to demonstrate function call nesting.

  28. Use the chop() function in a program. Print both the returned character and the string that was passed as a parameter.

  29. Run the following program to see how many levels of recursion your system configuration supports.
    firstSub();

    sub firstSub{
    print("$count\n");
    $count++;
    firstSub();
    }


  30. Write a function that uses the substr() and uc() functions to change the tenth through twenthieth characters to uppercase.

  31. Write a function that uses the keys() function to print out the values of an associative array.

  32. Create a program that uses a private function to subtract two numbers and multiply the result by four.

  33. Write a program that shows what the shift() and unshift() functions do.

  34. Write a program that shows what the push() and pop() functions do.

  35. Write a simple expression that uses the exponentiation operator.

  36. Write a complex expression that uses three operators and one function.

  37. Write a Perl program that uses a statement block inside a function call.

  38. Use the statement block from the previous exercise to create local variables.

  39. Write a Perl program that shows if the expression clause of a while modified statement will be evaluated when the condition is false.

  40. Use the while loop in a program to count from 1 to 100 in steps of 5.

  41. Use the for loop in a program to print each number from 55 to 1.

  42. Use an until loop, the next statement and the modulus operator to loop from 0 to 100 and print out "AAA" every 16th iteration.

  43. Use the foreach loop to determine the smallest element in an array.

  44. Use a for loop to iterate over an array and multiply each element by 3.

  45. Use a do..until loop and the each() function to iterate over an associative array looking for an value equal to "AAA". When the element is found, the loop should be ended.

  46. Write a program that will print the dereferenced value of $ref in the following line of code.
    $ref = \\\45;


  47. Write a function that removes the first element from each array passed to it. The return value of the function should be the number of elements removed from all arrays.

  48. Add error checking to the function written in exercise 4 so that the undef value is returned if one of the parameters is not an array.

  49. Write a program based on Listing 8.7 that adds a data member indicating which weekdays a salesman may call the customer with an id of MRD-300. Use the following as an example:
    "Best days to call" => ["Monday", "Thursday" ]


  50. Write a program to open a file and display each line along with its line number.

  51. Write a program that prints to four files at once.

  52. Write a program that gets the file statistics for /usr/bin/perl and displays its size in bytes.

  53. Write a program that uses the sysread() function. The program should first test the file for existence and determine the file size. Then the file size should be passed to the sysread() function as one of its parameters.

  54. Write a program that reads from the file handle in the following line of code. Read all of the input into an array and then sort and print the array.
     open(FILE, "dir *.pl |");


  55. Using the binary mode, write a program that reads the /usr/bin/perl and print any characters that are greater than or equal to "A" and less than or equal to "Z".

  56. Write a program that reads a file with two fields. The first field is a customer ID and the second field is the customer name. Use the ! character as a separator between the fields. Store the information into a hash with the customer id as the key and the customer name as the value.

  57. Write a program that reads a file into a array, then displays 20 lines at time.

  58. Write a pattern that matches either "top" or "topgun".

  59. Write a program that accepts input from STDIN and changes all instances of the letter a into the letter b.

  60. Write a pattern that stores the first character to follow a tab into pattern memory.

  61. Write a pattern that matches the letter g between 3 and 7 times.

  62. Write a program that finds repeated words in an input file and prints the repeated word and the line number on which it was found.

  63. Create a character class for octal numbers.

  64. Write a program that uses the translation operator to remove repeated instances of the tab character and then replaces the tab character with a space character.

  65. Write a pattern that matches either "top" or "topgun" using a zero-width positive look-ahead assertion.

13 nhận xét:

  1. aitiaptech dạy perl từ bao h thế thầy +_+ lâu ko vào i-php nhiều bài để đọc quá :p

    Trả lờiXóa
  2. aiti dạy pgp từ năm ngoái , nó là một môn thuộc kỳ 2 của chương trình mã nguồn mở .

    I-php sẽ cố gằng duy trì tần xuất 1 ngày 1 bài viết , em tham gia viết cho vui :D

    Trả lờiXóa
  3. em vào mãi ko được account hồi xưa :( công ty dạo này vui ko ạ hay em vào thực tập làm cùng mọi người được ko :D

    Trả lờiXóa
  4. bulk quantities wholesale of products to retail stores.Fortunately, there wholesale jeans is a wholesale company that stands out for its willingness to source to individuals as well as sellers. Rhinomart is the name of this wholesale source. The Rhinomart corporation does all of its business abercrombie and fitch online; this enables you to wholesale shoes search through Rhinomart’s wide-ranging inventory of available products and select what you want without ever having to leave the comfort of your own home. Of course, as is the case with normal wholesale businesses, you, the wholesale jerseys client, save more as wholesale shirts you buy more of a specific handbags good like dollar.

    Trả lờiXóa
  5. store merchandise Rado or even as seen on tv Rado watchesc products.This means that, although the omega watches price at a wholesaler is cheaper even for a rolex single product, the decision to obtain Replica Rado a bulk amount of umbrellas Breitling wholesale will end in you paying a far Cartier watches lower price than you wholesale Rado would pay if you only purchased.

    Trả lờiXóa
  6. Biggest DJs in the World. http://www.astateofsundays.net/ Trance, house, progressive music with the biggest DJs in the world.

    Trả lờiXóa
  7. Buy Dianabol in USA. Dianabol (D-bol) contains 10mg of Methandrostenolone per tablet http://www.terroids.com/product-gallery/orals/dbol . Manufactured for bodybuilders.

    Trả lờiXóa
  8. suhag raat ki video
    delete plz

    Trả lờiXóa
  9. Free hd pics, wallpapers 1080p - hd picture gallery. http://wallpapersfiles.com/

    Trả lờiXóa
  10. 1C:BIT http://www.1cbit.com/services/ specializes in enterprising software solutions and services for business management and analysis, accounting, finance management, resource planning, CRM, SRM and more.

    Trả lờiXóa