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:
a question about "read" function

 



shrimp_xia
Novice

Apr 17, 2002, 11:14 PM

Post #1 of 3 (660 views)
a question about "read" function Can't Post

my database "test.txt" is the flowing:
12345
6789
-----------
I want to print out the first 7 byte (12345 plus Wrap Prompt )

open (DDD,'test.txt');
read(DDD,$data,7);
close(DDD);
print $data;

because I know that the Wrap Prompt contain 2 bytes
but it show me the flowing result:
12345
6

please tell me what's wrong with it?


mhx
Enthusiast / Moderator

Apr 18, 2002, 3:10 AM

Post #2 of 3 (656 views)
Re: [shrimp_xia] a question about "read" function [In reply to] Can't Post

By default, open opens a file in text mode.
You need to switch to binary mode:


Code
open DDD,'test.txt'; 
binmode DDD;
read DDD, $data, 7;
close DDD;
print $data;


See [url=http://www.perldoc.com/perl5.6.1/pod/func/binmode.html]perldoc -f binmode for details.

-- mhx

At last with an effort he spoke, and wondered to hear his own words, as if some other will was using his small voice. "I will take the Ring," he said, "though I do not know the way."

-- Frodo



shrimp_xia
Novice

Apr 18, 2002, 3:16 AM

Post #3 of 3 (652 views)
Re: [mhx] a question about "read" function [In reply to] Can't Post

mhx : thank you for your warmheart....
thanks again :)

 
 


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

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