Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Khả năng cốt lõi số của Perl được hỗ trợ thông qua các nhà khai thác tiêu chuẩn mà bạn nên làm quen với. Ví dụ, tất cả các biểu thức sau trả lại giá trị mà bạn mong đợi: ost phần mềm được viết để làm việc và sửa đổi dữ liệu trong một định dạng này hay cách khác. Perl đã được thiết kế như một hệ thống để xử lý các bản ghi và tổng hợp, báo cáo | 460 Perl The Complete Reference l e. D or die Error in gzcat . Alternatively to write information and have it immediately compressed you can pass input directly to the gzip command Iopen COMPRESS gzip - file.gz or die Can t fork print COMPRESS Compressed Data close COMPRESS or die Gzip didn t work When using pipes you must check the return status of both open and close. This is because each function returns an error from a different element of the piped command. The open function forks a new process and executes the specified command. The return value of this operation trapped by open is the return value of the fork function. The new process is executed within a completely separate process and there is no way for open to obtain that error. This effectively means that the open will return true if the new process could be forked irrespective of the status of the command you are executing. The close function on the other hand picks up any errors generated by the executed process because it monitors the return value received from the child process via wait see the Creating Child Processes section later in this chapter . Therefore in the first example you could actually read nothing from the command and without checking the return status of close you might assume that the command failed to return any valid data. In the second example where you are writing to a piped command you need to be more careful. There is no way of determining the status of the opened command without immediately calling close which rather defeats the purpose. Instead you can use a signal handler on the PIPE signal. The process will receive a PIPE signal from the operating system if the piped command fails. Two-Way Communication As convenient as it may seem you can t do the following I open MORE more file This is because a pipe is unidirectional it either reads from or writes to a piped command. Although in theory this should work it can result in a deadlocked process where neither the parent nor .