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: Intermediate:
Using IO::All with binmode

 



delphipro9
New User

Nov 5, 2009, 12:24 PM

Post #1 of 3 (561 views)
Using IO::All with binmode Can't Post

Can someone enlighten me about how to use IO::All to create and output to a binary file. I can't get it to work at all.

This should work:
my $fo = io('BinaryFile.bin', 'w');
$fo->binmode();

$fo->print("This is a test\r\nThis is line 2\r\n");
$fo->close();

The above code should create a file with single-spaced lines, as \r\n is a carriage-return linefeed in Windows. However, I get a double-spaced file. It seems to ignore the "binmode".

This does work (using IO::File instead):

my $fo = IO::File->new('>myfile.bin');
$fo->binmode();
print $fo "Line 1\r\nLine 2\r\n";
$fo->close();

Now I get a single-spaced file, as I would expect.

What's the deal? Does IO::All not work for binary files?


(This post was edited by delphipro9 on Nov 5, 2009, 12:25 PM)


7stud
Enthusiast

Nov 5, 2009, 11:40 PM

Post #2 of 3 (553 views)
Re: [delphipro9] Using IO::All with binmode [In reply to] Can't Post

According to the IO::All docs:


Quote
Configuration Methods
...
...

binmode
Proxy for binmode. Requires a layer to be passed. Use binary for plain binary mode.


So I would try:

$fo->binary();


(This post was edited by 7stud on Nov 6, 2009, 12:22 AM)


delphipro9
New User

Nov 6, 2009, 5:58 AM

Post #3 of 3 (543 views)
Re: [7stud] Using IO::All with binmode [In reply to] Can't Post

Thanks. I'll give that a try.

 
 


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

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