A very simple subroutine that will replicate the entire script from which it was called. The only parameter it requires is a (scalar) prefix. NOTE: It benchmarks between 400 & 600% faster than using copy in Win32, and 40% faster than using cp in linux. (Via the system function.) -inno
sub replicate($){ if ($_[0]){ open Y, $0 || return 0; open Z, ">$_[0]$0" || return 0; print Z <Y> || return 0; close Z; close Y; return 1; } return 0; }
Or, somewhat simplified and a tad obfuscated:
sub replicate($){ $_ [0] && open (Y,$0) && open (Z , ">$_[0]$0" )&& print Z <Y> ?close Z && close Y && return 1:0 }
(Sorry I have an obfu fetish!)

Replies are listed 'Best First'.
•Re: Replicate Code
by merlyn (Sage) on Sep 20, 2002 at 16:19 UTC
      Let's see with 100000 iterations:

      Linux: 3% - 5% slower than File::Copy
      Win32: 25% - 30% faster than File::Copy

      -inno