| |||||||||||
| |||||||||||
Autovivification - the magic appearance of variables in Perl
Here's a one line perl program that does nothing but set up a variable ... except that it does a lot!
$p[7]{john}{paul}[9] = 1;If you assign to a variable in Perl and it does not already exist, the Perl creates it dynamically - and that implies that it also creates all the other necessary structures as well. My oneliner above took 10 lines to describe in plain English! This is both powerful and dangerous. Something as simple as $phone[1225708225] = 1;will give you "out of memory" as a list of over one billion elements is calledup. But do remember that $phone{1225708225} = 1;will create a hash with just one member, and THAT is what you should use for data with sparsely distributed numeric keys (written 2008-01-21 08:16:09) Associated topics are indexed under P217 - Perl - More than Simple Lists and Hashes!
Some other Articles
Downloading data for use in Excel (from PHP / MySQL)Python - formatting objects Pictures you can use - for free - from our library Keeping staff up to date on hotel room status Autovivification - the magic appearance of variables in Perl Perl, PHP or Python? No - Perl AND PHP AND Python! Summer Ball at Bowood - Saturday 12th July 2008 Buses from Well House Manor, Melksham, to Bath Handling Binary data (.gif file example) in Perl Extracting information from a file of records 1710 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, 34, 35 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 | |||||||||||