How about this:
Code:
#!/usr/bin/perl
use File::Copy;
move($oldfile, $newfile)
or die "move failed: $!";
OR if you want all the things done by hand, and not use some fancy library function
Code:
#!/usr/bin/perl
open(IN, "< $oldfile") or die "can't open $oldfile: $!";
open(OUT, "> $newfile") or die "can't open $newfile: $!";
$blksize = (stat IN)[11] || 16384; # preferred block size?
while ($len = sysread IN, $buf, $blksize) {
if (!defined $len) {
next if $! =~ /^Interrupted/; # ^Z and fg
die "System read error: $!\n";
}
$offset = 0;
while ($len) { # Handle partial writes.
defined($written = syswrite OUT, $buf, $len, $offset)
or die "System write error: $!\n";
$len -= $written;
$offset += $written;
};
}
close(IN);
close(OUT);
unlink($oldfile) or die "Can't unlink $oldfile: $!";
Naturaly you can change the $oldfile/$newfile with whatever you'd parsed as arguments.. I assume you know how to fetch arguments parsed to your program.
Else read up on the
Perl cookbook, happy reading
