My apologies for using incorrect syntax in my question. I thought I was responding to a previous thread, not creating a new one (thus, the lack sufficient information, I assumed it was already there).

Anyway, I rewritten the code, to make it a bit smaller. My situation is this: My school used to have their student/faculty login system setup, so each user loged in with their full name "First Last". This 'full name' was actually a psydonym for the real UNIX username, which was u character, followed by 3-5 addititonal digits (ie u881).

We have since upgraded to a new server, and while doing so, decided to change the real unix usernames, from numbers, to a short version of the user name

Gabriel Rigg, u881 becomes Gabriel Rigg, grigg

I have two files in my posession:
1) a file containing old usernumbers, and full names:
-------------------------usrbynum.txt---------------------
u880 name: Gabe Girard u881 name: Gabriel Rigg u882 name: Genna Bourget ... for about 263 of them
----------------------------EOF----------------------------
and 2) a file containing new shortnames, and full names
-------------------------srnames.txt-----------------------
fkasierderrick::1333:20::::Freya Kasier Derrick grigg::1460:20::::Gabriel Rigg omeara::1025:20::::Gary O'Meara
---------------------------EOF-----------------------------

There are a few issues to deal with. First, not everyone in short/full is in num/full, but I can deal with that later. However, here is my code:

#!/usr/bin/perl $oldserv = "./testing"; $newserv = "./testing2"; $usernumfile = "./usrbynum.txt"; $usershortfile = "./srnames.txt"; open USERNUMS, "< $usernumfile" or die "$!"; open SHORTNAMES, "< $usershortfile" or die "$!";# open file with user while (<SHORTNAMES>) { # loop through all lines of shor +tnames my ($longname,$shortname) = (split /:/)[7,0]; # seperat +e by those ugly colen $finishedusers{$longname} = $shortname; chomp %finishedusers; } my %lookup; # Hash %lookup while(<USERNUMS>) { # loop through file with user numbers ($uid) = /(u\d{3,5})/; # User ID find yes ($longname2) = /([A-Z]\w+)/; chomp $longname2; $lookup{$longname2} = $uid; # Setup hash %lookup with keys " +Long Name"=> "usernum" } while (($longname2, $uid) = each(%lookup)) { next unless exists $finishedusers{$longname2}; system ("cp '$oldserv/$uid/Documents/*' '$newserv/$finishedusers{$ +longname2}/Documents/'"); print "Copying Files for $finishedusers{longname2}"; } close USERNUMS; close SHORTNAMES;

To test whether or not the hashes of the different files were working, I commented most of the code out, and told it to to print to the screen. For example:
while (<SHORTNAMES>) { # loop through all lines of shor +tnames my ($longname,$shortname) = (split /:/)[7,0]; # seperat +e by those ugly colen $finishedusers{$longname} = $shortname; chomp %finishedusers; } while (($templong,$tempshort) = each(%finishedusers)) { print "long: $templong \n short: $tempshort \n\n }
For both of the files and their while() statements used to extract data for the hashes, they printed the exact correct statements (even the newlines added up, so there were none because of the chomp). So, I know that, individually at least, these statements work.

The final few lines of the code is supposed to match shortnames to old usernumbers, via a matching long name (since its the shared constant between the files), and move all the files from the old usernumber/Directory to the short/Directory.

I added 'use strict; use warnings;', and got the following output:
Global symbol "$oldserv" requires explicit package name at doctrans2.p +l line 6. Global symbol "$newserv" requires explicit package name at doctrans2.p +l line 7. Global symbol "$usernumfile" requires explicit package name at doctran +s2.pl line 8. Global symbol "$usershortfile" requires explicit package name at doctr +ans2.pl line 9. Global symbol "$usernumfile" requires explicit package name at doctran +s2.pl line 11. Global symbol "$usershortfile" requires explicit package name at doctr +ans2.pl line 12. Global symbol "%finishedusers" requires explicit package name at doctr +ans2.pl line 15. Global symbol "%finishedusers" requires explicit package name at doctr +ans2.pl line 16. Global symbol "$uid" requires explicit package name at doctrans2.pl li +ne 21. Global symbol "$longname2" requires explicit package name at doctrans2 +.pl line 22. Global symbol "$longname2" requires explicit package name at doctrans2 +.pl line 23. Global symbol "$longname2" requires explicit package name at doctrans2 +.pl line 24. Global symbol "$uid" requires explicit package name at doctrans2.pl li +ne 24. Global symbol "$longname2" requires explicit package name at doctrans2 +.pl line 27. Global symbol "$uid" requires explicit package name at doctrans2.pl li +ne 27. Global symbol "%finishedusers" requires explicit package name at doctr +ans2.pl line 28. Global symbol "$longname2" requires explicit package name at doctrans2 +.pl line 28. Global symbol "$oldserv" requires explicit package name at doctrans2.p +l line 29. Global symbol "$uid" requires explicit package name at doctrans2.pl li +ne 29. Global symbol "$newserv" requires explicit package name at doctrans2.p +l line 29. Global symbol "%finishedusers" requires explicit package name at doctr +ans2.pl line 29. Global symbol "$longname2" requires explicit package name at doctrans2 +.pl line 29. Global symbol "%finishedusers" requires explicit package name at doctr +ans2.pl line 30. Execution of doctrans2.pl aborted due to compilation errors.

However, without use strict and use warnings, the code execute with no errors, but no results.

Expected result was that a file ./testing/u881/Documents/test.txt would be moved to ./testing2/grigg/Documents/ . However, it does not get moved (obviously).

Any suggestions?

In reply to Still having problems with user 'backup' script by gsr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.