Wednesday, December 26, 2012

Perl 에서 binary file 읽고 쓰기

 #!/usr/bin/perl -w  
 #Source: http://perlmeme.org/faqs/system/binmode.html  
 use strict;  
 use warnings;  
   
 my $buffer;  
 my $num_bytes = 1024;  
 my $infile = "test.png";  
 my $outfile = "test2.png";  
   
 open (INFILE, $infile) or die "Couldn't open $infile for reading: $!";  
 open (OUTFILE, ">$outfile") or die "Couldn't open $outfile for writing: $!";  
 binmode(INFILE);  
 binmode (OUTFILE);  
   
 while (read(INFILE, $buffer, $num_bytes)) {  
      print OUTFILE $buffer;  
 }  
 close INFILE;  
 close OUTFILE;  
 exit 0;  
How do I write binary files on a non-Unix OS?
키워드 : binmode, read, write

No comments:

Post a Comment