Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Binary Mode to Ascii Mode

Status
Not open for further replies.

wood

MIS
Aug 3, 2000
139
CA
I have a perl script where I am writing a file using regular ascii mode, then I need to write anther file using binmode. This all workd fine. Now I want to open another file read it, and write it again (using ascii mode).

How do I change back to ascii mode once in binmode?
 
use a different filehandle would be my choice

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
I am fairly new to this, so please bear with me.

I believe that I am using another file handle. Please see the code below.

Code:
binmode STDOUT;

# Convert the image to PNG and send it to a file.
my $PNG = new IO::File "> $epod_file";
print $PNG $im->png(0);
close($PNG);
		
my $epod_file2 = "/var/[URL unfurl="true"]www/img_tmp$SessionID.epod.$now.tiff";[/URL]
my $img2 = Imager->new(xsize=>600, ysize=>700);
$img2->read(file=>$epod_file, type=>'png') or die "Cannot read $epod_file: ", $img2->errstr;
$img2->write(file=>$epod_file2, type=>'tiff') or die "Cannot write $epod_file2: ", $img2->errstr;

What happens is I get the error that says cannot write file.
 
Code:
open FH, ">$epod_file";
binmode(FH);
print FH $im->png(0);
close FH;

I've no idea why you're setting STDOUT to binary mode, or using IO::File ??

Which error are you getting? And what is Imager?

Ascii mode for image files, doesn't sound right, are you sure this is what you want to do ...?

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
I am using the GD module, and to write the image, it requires that I change to binary mode.

Imager is another module that allow me to open the image and save it as another format.

I am opening images and saving them above the code I inserted, and that works fine.

And, no, I am not exactly sure if this will fix the error problem.

The exact error is: Cannot write /var/ at /var/ line 214.
 
I have figured out my problem, and attached the code.

Code:
my $PNG = new IO::File "> $epod_file";
binmode($PNG);
print $PNG $im->png;
close($PNG);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top