| Start |
|---|
| Array as list The array is one of Perl's basic variable types. It contains a list, which is an ordered sequence of zero or more scalars. The array is the variable holding (and providing access to) the list data, as is documented in perldata (opens new window). You can assign a list to an array: You can use an array wherever a list is expected: Some operators only work with arrays since they mutate the list an array contains: |
| Assigning a list to a hash Lists can also be assigned to hash variables. When creating a list that will be assigned to a hash variable, it is recommended to use the fat comma The You can also use quoted strings for the left hand operand of the fat comma For details see Comma operator (opens new window) at |
| Lists can be passed into subroutines As to pass list into a subroutine, you specify the subroutine's name and then supply the list to it: Internally Perl makes aliases to those arguments and put them into the array You access subroutine arguments like this: Aliasing gives you the ability to change the original value of argument passed to subroutine: To prevent inadvertent changes of original values passed into your subroutine, you should copy them: To test how many arguments were passed into the subroutine, check the size of If you pass array arguments into a subroutine they all will be flattened: If your |
| Return list from subroutine You can, of course, return lists from subs: But it is not the recommended way to do that unless you know what you are doing. While this is OK when the result is in LIST context, in SCALAR context things are unclear. Let's take a look at the next line: Why
In most cases the right strategy will return references to data structures. Then the caller does something like this to receive the two returned arrayrefs: |
| Hash as list In list context hash is flattened. The array
It is guaranteed that key-value pairs goes together. Keys are always even indexed, values - odd. It is not guaranteed that key-value pairs are always flattened in same order: |
| Using arrayref to pass array to sub The arrayref for |
Read Article
https://develop.horje.com/learn/1434/reference