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.


In reply to Has my Perl Go Crazy? by Xanthis013

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.