grocery_stocker
Jul 3 2005, 12:15 AM
Given the following lines of code:
#!/usr/bin/perl
#Just move all the backup files created by emacs to a dummy directory
my $current_dir = "pwd";
my $command = "cp";
my $backup_dir = "/backup/";
my $dest_dir = "current_dir" . "backup_dir";
my $search_dir = 'ls *.pl~';
open(MOVE, " $command");
I don't know how to have perl move the files with the ~ to the backup
directory.
I did try something like:
@ARGV = `ls *.c~`;
$total = scalar(@ARGV);
for($i=0;$i<$total;$i++) {
`cp $ARGV[$i] $dest_dir `
}
But it didn't work. Any ideas?
cgavos
Jul 3 2005, 10:56 AM
You need something like that
#!/usr/bin/perl
use warnings;
use strict;
my $current_dir=`pwd`;
## Note these are note single
## quotes this is a backquote
## in a uk keyboard is located above the tab key
chop($current_dir);
my $command=`which cp`; #backquote
chop($command); # remove n character
my $backup_dir="/path/to/destination/";
## absolute path to
## destination with trailing /
my @search_dir=`ls *.pl~`;#backquote
my $full_cmd;
for (my $i=0; $i<$#search_dir; $i++) {
chop($search_dir[$i]);
$full_cmd="$command $current_dir/$search_dir[$i] $backup_dir";
print "$full_cmdn";
## Once you are happy with the command to be executed
# uncomment the following line
# system($full_cmd);
}