Xanthis013 has asked for the wisdom of the Perl Monks concerning the following question:
I work at a company that has many programmers, but only one or two know perl well, the rest write code in other languages.
I am writing a script that I will use to take files from one network drive, archive the files in another, then encrypt and FTP out the files to a vendor.
I was doing well.
I had the script copying, moving, encrypting and FTPing the files as needed. Those files have static names. But then came a set of files that from one week to the next there can be one to four files.
A friend helped me write a sub for the move that went something like this.
sub childsup{ print `dir /b $source\\*.txt > $source\\dir_list.lst`; #$source is d +eclared just before the sub is called print `copy $source\\dir_list.lst $script\\dir_list.lst`; #this copy + works just fine. open (DIR, "$source\\dir_list.lst") ||die "Can't Open list file"; @list=<DIR>; close (DIR); $cnt = 0; Problems start here foreach $tmp(@list) #This is the section which is meant copy/move + several files to other Directories. This is the first and only time +I use an Array in the script ‘ @list‘ all other moves or copies are d +one for one file and that file has a static name. The point of the mo +ve/copy is to archive and encrypt with PGP to send to a site via FTP. { use File::Copy; $csfile = "\\$tmp"; $csarch = "\\\\hal\\public\\public\\boa\\archive"; #print "copy $source\\$tmp $dest\\$tmp"; #This prints what the nex +t line should do, and the output is correct. #print `copy $source\\$tmp $dest\\$tmp`; #This line will copy the +file to the script directory instead of where it should go. #print `move \\\\hal\\Public\\Public\\BOA\\$tmp \\\\hal\\Public\\P +ublic\\BOA\\archive\\$tmp`; #This line will move the file to the script directory in +stead of where it should go. #copy("\\\\hal\\Public\\Public\\BOA\\$tmp", "\\\\hal\\Public\\Publ +ic\\BOA\\archive\\$tmp") || warn "File not moved $!"; # Here I use the perl File::Copy function as called above. But the scr +ipt will output File not moved No such file or directory at Y:\SunTr +ust\scripts\Bank_master4.pl line 278. Although the files are there. move("$source\\$tmp", "$dest\\$tmp") || warn "$tmp could not be mo +ved $!"; # Here I use the perl File::Copy function as called above. +But the script will output payroll_positive_pay.txt could not be move +d Permission denied at Y:\SunTrust\scripts\Bank_master4.pl line 279. $cnt = $cnt +1; } if ($cnt < 1) { system("cls"); system("color cf"); print "\n"; print "\n"; print "There are no file is available.\n"; print "\n"; print "Please verify manually.\n"; print "\n"; $avil = 1; print `pause`; } }
So the issue here is has anyone had a script that in a move or copy although the syntax was correct and the logic was sound, would consistently move or copy the files to the wrong place.
This error is infectious. I wrote another part of a script, I actually copied a portion and redirected that directories. But this time instead of moving the files to the folder where the script resides, it moved them to the root of the network drive where the script resides. This is all really weird. I ask what am I not seeing.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Has my Perl Go Crazy?
by AnomalousMonk (Archbishop) on Aug 27, 2008 at 05:02 UTC | |
by scorpio17 (Canon) on Aug 27, 2008 at 15:33 UTC | |
by jdporter (Paladin) on Aug 27, 2008 at 15:51 UTC | |
|
Re: Has my Perl Go Crazy?
by Tanktalus (Canon) on Aug 27, 2008 at 04:34 UTC | |
|
Re: Has my Perl Go Crazy?
by GrandFather (Saint) on Aug 27, 2008 at 04:36 UTC | |
|
Re: Has my Perl Go Crazy?
by TGI (Parson) on Aug 28, 2008 at 02:21 UTC | |
|
Re: Has my Perl Go Crazy?
by Xanthis013 (Initiate) on Aug 31, 2008 at 05:17 UTC |