TAILIEUCHUNG - Beginning Perl Third Edition PHẦN 8

của tôi $ Galileo = người (". 9,81 Pisa Apts" Họ = "Galilei", firstname = "Galileo", địa chỉ =, nghề nghiệp = "bombadier",); Ngoài ra còn có một cú pháp gọi phương pháp, mà bạn sẽ đặc biệt được sử dụng với xây dựng: $ Galileo = new Person (.); các nhà xây dựng sẽ kiểm tra các đối số có thể chấp nhận được, | CHAPTER 13 OBJECT-ORIENTED PERL my galileo lastname firstname address occupation Person- new Galilei Galileo Pisa Apts. bombadier There s also another syntax for calling methods which you ll particularly see used with the constructor my galileo new Person . The constructor will now check that the arguments are acceptable do any conversion it requires and create a hash reference bless it and return it to us. More on this later in this chapter. Destructors When the object is no longer in use when it s a lexical variable that goes out of scope Perl automatically destroys it. However before doing so Perl will attempt to call a method named DESTROY . If the class provides this method it should be responsible for any tasks that need to be performed before the object is disposed of. For instance your FTP session object will want to ensure that it has closed the connection to the remote server. An Example It is now time for an example. Let s start off by using a class that is already created for us Net This class also known as a module allows you to create objects that transfer files to and from an FTP server. The following example will connect to the CPAN and download the file. This example will illustrate some of the buzz words mentioned previously. usr bin perl use strict use Net FTP my ftp Net FTP- new or die Couldn t connect @ n ftp- login anonymous ftp- cwd pub CPAN ftp- get ftp- close 2 This code was written by Graham Barr. Thanks Graham 292 CHAPTER 13 OBJECT-ORIENTED PERL Network and firewalls permitting this should retrieve the file although it may take some time. Here is the proof on a Windows machine perl dir README 1 HTM 2 902 . The first line of interest in this program is use Net FTP This line finds the file that contains the definition of the Net FTP class as you learned in Chapter 12 its name happens to be and it is located in a directory named Net and compiles it .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.