#!/usr/bin/perl # Make sure there is a forward slash at the beginning of each string for oldserv and newserv $oldserv = "./testing"; $newserv = "./testing2"; $usernumfile = "./usrbynum.txt"; $usershortfile = "./srnames.txt"; open USERNUMS, "< $usernumfile" or die "$!"; # open file with user numbers open SHORTNAMES, "< $usershortfile" or die "$!";# open file with user shortnames while () { # loop through all lines of shortnames my @array2 = split /:/; # seperate by those ugly colens created by OSX $finishedusers{$array2[7]} = $array2[0];# Setup keys: "Long Name" => "shortname" } my %lookup; # Hash %lookup while() { # loop through file with user numbers ($v,$k) = /(u\d{3,5})\s+real: (.*?)\s*/;# $v = User ID (u followed by 3-5 digits) $k = Full Name $lookup{$k} = $v; # Setup hash %lookup with keys "Long Name" => "usernum" } %finishedusers = reverse %finishedusers; # Get rid of those fscking duplicates my %final; # Hash %final while (($fullname, $uid) = each(%final)) { # Loop through hash while (($fullname2, $short) = each(%finishedusers)) { # another loop. its hash squared! if ($fullname eq $fullname2) { system ("cp '$oldserv/$uid/Documents/*' '$newserv/$short/Documents/'"); print "Copying Files for $fullname"; } } }