in reply to Moving Files

Learning Perl ... Randal et al: exercise: 5, chap12. rename is your friend. You could also use File::Base - holy ones would be able to ratify this better :-). I had written the following code as a solution to the exercise... the code requires that you work from your dir1 (i.e. the folder in which you have all the files to be moved) - it is buggy - please be warned (as I'd written this as a n00b and haven't had time to debug it since).
#!/usr/bin/perl use strict; use warnings; if ($#ARGV > 1) { print "ARGV greater than 1\n"; unless (-e $ARGV[$#ARGV]) { mkdir $ARGV[$#ARGV], 0755 or die "Cannot create directory: + $!"; } my $dir = $ARGV[$#ARGV]; my $last=$#ARGV-1; foreach (0..$last) { if (-f $ARGV[$_]) { if (-e "$ARGV[$#ARGV]/$ARGV[$_]") { print "$ARGV[$#ARGV]/$ARGV[$_]\n"; print "File $ARGV[$_] already exists in $AR +GV[$#ARGV]\n"; print "Overwrite?:(y/n)\n"; chomp (my $line = <STDIN>); next if ($line =~ /^(\s.*|n)/i); } my $old = "$ARGV[$_]"; my $new = "$dir/$ARGV[$_]"; rename $old, $new; } } } if ($#ARGV == 1) { print "ARGV equal to 1\n"; if (-f $ARGV[0]) { rename $ARGV[0], $ARGV[1]; } if (-d $ARGV[0]) { unless (-e $ARGV[1]) { mkdir $ARGV[1], 0755 or die "Cannot create directory: $!", } if (-e "$ARGV[1]/$ARGV[0]") { print "File $ARGV[0] already exists in $ARGV[1]\n"; print "Overwrite?:(y/n)\n"; chomp (my $line = <STDIN>); last if ($line =~ /^(\s.*|n)/i); } foreach my $file (glob "$ARGV[0]/*") { my $oldfile = $file; $file =~ s/$ARGV[0]/$ARGV[1]/; rename $oldfile, $file; } } } if ($#ARGV < 1) { print "ARGV less than 1\n"; print "There should be atleast two arguments for this to work\n"; last; }