| |||||||||||
| |||||||||||
Returning multiple values from a function (Perl, PHP, Python)
Function in PHP and Python and subs in Perl can only return one "thing" - one item, one object. But all three languages allow that returned item to be a collection - in other words, a composite. And all three languages provide a very easy way of breaking the returned structure down into a series of individual variables.
Python Example returning a tuple # Returning a tuple from a functionPHP Example returning into the list function <?phpPerl Example Saving the returned values to a list sub sistance {In each case, the techniques shown above should be used when you want to return multiple values in strong preference to global variables - your code will be much more modular and easy to maintain if you follow the approach shown. (written 2007-05-24 18:39:40) Associated topics are indexed under H105 - PHP - FunctionsY105 - Python - Functions, Modules and Packages P209 - Subroutines in Perl
Some other Articles
Where and When - can you place the picture?Arrival and Departure experiences - another hotel Spot the difference A Fresh horse Returning multiple values from a function (Perl, PHP, Python) No switch in Python Training information - England, Scotland, Wales and Ireland Testing for one of a list of values. From Web to Web 2 Back off home with our best wishes 1634 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33 at 50 posts per pageThis is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price. Link to Ezine home page (for reading). Link to Blogging home page (to add comments). |
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 707126 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho | |||||||||||