| |||||||||||
| |||||||||||
Passing several lists to a sub Posted by enquirer (enquirer), 17 March 2005 How do I pass in several lists to a sub in Perl and avoid the contents of them all getting lumped together?Posted by admin (Graham Ellis), 17 March 2005 In Perl, you call subs with a list as their parameter - so if you simply provide a number of comma separated lists in the call then they'll all get combined into a single list ... not what you want much of the time.The solution is to use the \ operator to pass the ADDRESS of each list into the sub; it makes the internal code in the sub slightly more complex, but it cures the problem. Example: Code:
Runs: Code:
Note too how I've used square rather than round brackets to pass in the address of anonymous list(s) ... This page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
|
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |