CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Reading data from a bitmap

 



martin
stranger

Jul 30, 2001, 2:31 PM

Post #1 of 3 (582 views)
Reading data from a bitmap Can't Post

I'm trying to write a perl program to take a bitmap file examine the contents and place the contents in a data file. The problem is that occasionally my program seems to finish prematurely before the whole bitmap has been read in. I suspect that some of the RGB number codes are being misinterpreted as a new line or end of file character but I can't seem to work around this. Can anyone tell me where I'm going wrong as I'm pulling my hair out!



mhx
Enthusiast / Moderator

Jul 30, 2001, 10:24 PM

Post #2 of 3 (576 views)
Re: Reading data from a bitmap [In reply to] Can't Post

If you're working under Windows, you must explicitly put all your filehandles in binary mode:

Code
open FILEHANDLE, $file or die $!; 
binmode FILEHANDLE;
# do something with FILEHANDLE
close FILEHANDLE;

Additionally, I've noticed that you use the readline operator (<FILEHANDLE>) for reading the file. This will only work if the $/ variable is undefined, otherwise the file will only be read up to the string stored in $/, which is normally a newline character sequence. So I'd use

Code
open RAWTEXT, $ChosenFile or die "cannot open $ChosenFile: $!"; 
binmode RAWTEXT;
$imagedata = do { local $/=undef; <RAWTEXT> };
close RAWTEXT or die "cannot close $ChosenFile: $!";

Hope this helps.

-- Marcus


Code
s$$ab21b8d15c3d97bd6317286d$;$"=547269736;split'i',join$,,map{chr(($*+= 
($">>=1)&1?-hex:hex)+0140)}/./g;$"=chr$";s;.;\u$&;for@_[0,2];print"@_,"



martin
stranger

Jul 31, 2001, 1:40 AM

Post #3 of 3 (573 views)
Re: Reading data from a bitmap [In reply to] Can't Post

Schweet!

Thanks Marcus, worked first time!!


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives