TAILIEUCHUNG - Minimal Perl For UNIX and Linux People 8

Cú pháp sử dụng các mảng trong Shell Shell và Perl Perl $ n [0] = 13, Ghi chú Trong Perl, ký hiệu $ luôn luôn được sử dụng với các tên biến khi đề cập đến một giá trị vô hướng. Với Shell, nó chỉ được sử dụng khi lấy một giá trị. Shell yêu cầu tên mảng và chỉ số để được kèm theo trong dấu ngoặc nhọn. Xóa Shell yếu tố được chỉ định, nhưng Perl duy trì khe của phần tử sau khi đánh dấu giá trị của nó là không xác định. Shell công nhận. | Table Syntax for using arrays in the Shell and Perl Shell Perl a Remarks Assigning a value n 0 13 n 0 13 In Perl the symbol is always used with the variable name when referring to a scalar value. With the Shell it s only used when retrieving a value. Retrieving and displaying a value echo n 0 print n 0 The Shell requires the array name and index to be enclosed in curly braces. Deleting a value unset n 0 delete n 0 The Shell deletes the designated element but Perl maintains the element s slot after marking its value as undefined. Assigning multiple values n 13 42 @n 13 42 @n qw 13 42 @n qw The Shell recognizes whitespace as separators in the parenthesized list of initializers. By default Perl requires a comma and allows additional whitespace. With the qwX syntax only whitespace separators are recognized between paired occurrences of the X Retrieving and displaying all values echo n @ print @n See text for explanation. a. The examples using print assume the use of Perl s l invocation option. b. Examples of the qwX quoting syntax are shown in chapter 12. As shown in the table s last row the Shell uses the special @ index to retrieve all values preserve any whitespace within them and separate them from each other by a space. As usual double quotes are also required if further processing of the extracted values isn t desired. With Perl on the other hand all values are retrieved by using the array name without an index. The only effect of the double quotes is to separate the values on output with the contents of the variable they re not needed to suppress further processing of the extracted values because that doesn t happen Next we ll look at different ways to initialize arrays. 2 See http for details on the comparative use of double quotes in the two languages. 298 CHAPTER 9 List variables Initializing arrays with piecemeal assignments and push As shown in the top row of table you can .

TỪ KHÓA LIÊN QUAN
Đã 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.