Bài tập Perl
22/02/2012 - Xem: 2577
Bài tập thực hành – Dùng trong môn perl programing Aiti-aptech
Perl Exercises
- Create and run a Perl program that prints “Hello, World” on the monitor.
- Write a program that prints the decimal number 32. However, in the print command, specify the value of 32 using hexadecimal notation.
- Create program that uses the tab character in three literals to align text.
- Write a program that prints using metaded new lines in a single-quoted literal.
- Convert the number 56,500,000 into scientific notation.
- 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?
- Write a program that prints its own source code
- Create a array called @months. It should have 12 elements in it with the names of the month represented as strings.
- Create a string that interpolates that value of the variable $numberOfBooks.
- Using the range operator (..) create an array with the following elements: 1, 5, 6, 7, 10, 11, 12.
- Using the array created in the last exercise, create a print command to display the last element.
- 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.
- Using the array created in the last exercise, create a print command to display the last element.
- Assign a value to $firstVar using both division and subtraction.
- Using the post-decrement operator, subtract one from $firstVar.
- 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.
- Use the **= assignment operator to assign a value to $firstVar.
- Use the ternary operator to decide between to different value.
- 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.
- Use the concatenation operator to join the following values together: “A” x 4 and “B” x 3.
- Use the exponentiation operator to find the value of 2 to the 5th power.
- Write an assignment statement that uses the && and || and ! operators.
- Write a program that prints the value of the fifth bit from the right in a scalar variable.
- Write a program that uses a bitwise assignment to set the fifth bit from the right in a scalar variable.
- Write a program that shows the difference in operator precedence between the % operator and the && operator.
- Create a function that prints its own parameter list.
- Create a program that uses three functions to demonstrate function call nesting.
- Use the chop() function in a program. Print both the returned character and the string that was passed as a parameter.
- Run the following program to see how many levels of recursion your system configuration supports.
firstSub(); sub firstSub{ print("$count\n"); $count++; firstSub(); }
- Write a function that uses the substr() and uc() functions to change the tenth through twenthieth characters to uppercase.
- Write a function that uses the keys() function to print out the values of an associative array.
- Create a program that uses a private function to subtract two numbers and multiply the result by four.
- Write a program that shows what the shift() and unshift() functions do.
- Write a program that shows what the push() and pop() functions do.
- Write a simple expression that uses the exponentiation operator.
- Write a complex expression that uses three operators and one function.
- Write a Perl program that uses a statement block inside a function call.
- Use the statement block from the previous exercise to create local variables.
- Write a Perl program that shows if the expression clause of a while modified statement will be evaluated when the condition is false.
- Use the while loop in a program to count from 1 to 100 in steps of 5.
- Use the for loop in a program to print each number from 55 to 1.
- Use an until loop, the next statement and the modulus operator to loop from 0 to 100 and print out “AAA” every 16th iteration.
- Use the foreach loop to determine the smallest element in an array.
- Use a for loop to iterate over an array and multiply each element by 3.
- 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.
- Write a program that will print the dereferenced value of $ref in the following line of code.
$ref = \\\45;
- 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.
- 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.
- 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" ]
- Write a program to open a file and display each line along with its line number.
- Write a program that prints to four files at once.
- Write a program that gets the file statistics for /usr/bin/perl and displays its size in bytes.
- 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.
- 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 |");
- 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”.
- 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.
- Write a program that reads a file into a array, then displays 20 lines at time.
- Write a pattern that matches either “top” or “topgun”.
- Write a program that accepts input from STDIN and changes all instances of the letter a into the letter b.
- Write a pattern that stores the first character to follow a tab into pattern memory.
- Write a pattern that matches the letter g between 3 and 7 times.
- 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.
- Create a character class for octal numbers.
- 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.
- Write a pattern that matches either “top” or “topgun” using a zero-width positive look-ahead assertion.
(i-php.net)
Tin sưu tầm:
Các tin khác cùng chuyên mục
- Kỹ thuật lập trình HTML/CSS mới nhất 2020 - 04
- Funny web2.0
- Giải thử vài câu đề thi tốt nghiệp ptth môn toán
- MỘT NGÀY PHẢI KHÁC MỌI NGÀY
- Level 1 - Lập trình hướng đối tượng (P2)
- Level 1 - Lập trình hướng đối tượng (P1)
- PHP 5.3, Phần 3: Không gian tên
- PHP 5.3, Phần 2: Bao đóng và các hàm lambda
- PHP 5.3, Phần 1: Các thay đổi về giao diện đối tượng
- Tăng tốc độ xử lý CSDL MySQL
Liên kết
Tin được quan tâm nhất
- Ant Group của Jack Ma hé lộ bước đi đầu tiên...
- Ô tô giao hàng tự lái sẽ bắt đầu hoạt...
- Clip cô giáo phạt học sinh tự ném vỡ...
- Tiền điện tử lớn thứ ba thế giới Ripple...
- Joe Biden kêu gọi hiện đại hóa hệ thống...
- Viettel khai trương nền tảng Hồ sơ sức khỏe...
- Các hãng di động nên ngừng cãi nhau về việc...
- Công nghệ AI của Alibaba và Tân Hoa Xã: Đối...
- Một năm đáng thất vọng của YouTube trên toàn...
- EVN lần đầu diễn tập an toàn thông tin mạng...
- Đây là chiếc iPhone được mua nhiều nhất...
- Bộ Tài chính ra quy chế mới về quản lý, sử...
- Cập nhật nhãn mới giúp người tiêu dùng...
- Kiếm tiền từ 5G: Thách thức lớn nhất của...
- "Hô biến" iPhone thành cục đá: Có thể bị...
- Phí trước bạ ô tô không gia hạn giảm, sẽ...
- Tại sao Apple chế tạo ô tô?
- Viettel cung cấp dịch vụ 5G tại thành phố...
- Đội KingTigerPrawn của Hàn Quốc giành giải...
- Thứ trưởng Phan Tâm: “Triển khai hạ tầng 5G...
- Nhiều mẫu iPhone chính hãng đang khan hàng tại...
- Mỹ quy định drone cần có ID, trang bị đèn ban...
- Trung Quốc điều tra Alibaba: Bài học cho Jack Ma...
- Chuyên gia dự báo 5 xu hướng tấn công mạng...
- Apple MagSafe vẫn còn rất nửa vời
- Các tỉnh cuối cùng đã ngừng phát sóng...
- 55/63 tỉnh thành sử dụng Zalo trong cải cách...
- Headline: CR7: “Mong muốn của tôi là luôn...
- Samsung dự kiến xuất xưởng dưới 300 triệu...
- Vì sao Trung Quốc ‘sờ gáy’ Alibaba?
- Những smartphone được người Việt mua nhiều...
- Vì sao mua hàng ở sàn TMĐT Mỹ không cần...
- Đằng sau bức ảnh động viên Đà Nẵng chiến...
- VNPT cung cấp MyTV Box 2020 - Tính năng nâng cấp...
- Clip hành động ghê tởm của shipper trước khi...
- Các đội thi chung kết WhiteHat Grand Prix 6 phát...