| |||||||||||
| |||||||||||
Handling Binary data (.gif file example) in Perl
Perl is very good for handling binary data - it can do things you can't do with other utilities and scripting languages, and things that are very much harder to do in C - that's because C's strings are null terminated and in the case on binary strings, there may be an embedded null anywhere.
Finding good examples is a bit tricky. And that's because binary data tends to come with long and involved specifications. However, a .gif image file has the height and width of the image encoded into the 7th to 10th bytes of the file, so that does make a reasonable example # Find all files ending in ".gif" in current directoryI've put plenty of comments into that code ... good practice ... and so there's not much need for extra detailed description here. But I should add that there's a pack function that's the opposite of unpack if you want to reform binary data, and you can output binary data using the regular print function - nothing special at all is needed. Yes - it's Perl, yes the code is that short, and when you know the language really well you can write it REALLY quickly! (written 2008-01-17 21:36:06) Associated topics are indexed under P212 - Perl - More on Character Strings
Some other Articles
Autovivification - the magic appearance of variables in PerlPerl, 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 How not to write Perl? Comments on proposed Asda Superstore for Melksham Ongoing Image Copyright Issues, PHP and MySQL solutions Script to present commonly used images - PHP 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 | |||||||||||