SWIG and Automated C/C++ Scripting Extensions
By David Beazley
Dr. Dobb's Journal February 1998
use stdio; sub filecopy { my ($source,$target) = @_; my $f1 = stdio::fopen($source,"r"); my $f2 = stdio::fopen($target,"w"); my $buffer = stdio::malloc(8192); my $nbytes = stdio::fread($buffer,1,8192,$f1); while ($nbytes > 0) { stdio::fwrite($buffer,1,8192,$f2); $nbytes = stdio::fread($buffer,1,8192,$f1); } stdio::free($buffer); stdio::fclose($f1); stdio::fclose($f2); }
Example 4: Perl script to copy a file (using functions in Example 3).
Copyright © 1998, Dr. Dobb's Journal