Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Compare Inventory to Database and Vice-Versa

by Hellhound4 (Novice)
on Mar 21, 2012 at 23:41 UTC ( #960889=perlquestion: print w/ replies, xml ) Need Help??
Hellhound4 has asked for the wisdom of the Perl Monks concerning the following question:

So my first post here. I'm looking for a way to take a list of file names (one file name per line) and compare it to the contents of a few directories. What's happening is at work we store files in directories like: //server/project/filetype/batch number/file.pdf However the database will export a .txt file containing all the files that SHOULD be in the directories. Here's the catch not all of the file names from the database reside in the same batch number location. I need to know how to substitute the "number" part of the directory above with a variable the user inputs. I also need to know if a file is not in the directory that should be. OR if a file is in the directory and not the list. And lastly not all files from the list will be in each directory but all files should be accounted for at the end of ALL directories.

Comment on Compare Inventory to Database and Vice-Versa
Re: Compare Inventory to Database and Vice-Versa
by GrandFather (Cardinal) on Mar 22, 2012 at 00:06 UTC

    So what have you tried and what didn't work? What Perl documentation have you read? Have you looked through the Tutorials section? Have you any other programming experience?

    When reading through documentation take special note of anything that mentions the word "hash". Perl's hash data structure is the key to much of what you want to do. Another key Perl feature is likely to be regular expressions - see perlretut.

    True laziness is hard work
      I have experience in C++ and (recently) VBA I've actually written the program in VBA but it only throws an error if there is something in the database and not the directory. But I would like to know if there is something hanging out in my directories that shouldn't be there as well. And I am reading the tutorials right now. Most of my questions are about syntax and perl specific issues. For example if I make this on my linux pc at home will I have to change anything other than directory name on the windows pc at work.
        On a different note... Is there a way to edit my own reply's? I see where to edit my post. But not my replys.

        If you've written it in VBA then rewriting in Perl should be a snap! Perl has much better, well everything really, than VBA, but especially string manipulation, control structures and data structures. You'll find Perl is much closer to C++ in many ways than to VBA.

        As I said earlier, hashes are the key. Think STL's map class.

        For standard sorts of stuff Perl is very portable. For what you have described so far you should be able to move your *nix script to a Windows box unchanged. Note that Perl will even "do the right thing" with native line endings so on *nix it uses line feeds and on Windows carriage return line feed pairs when reading and writing files by default. A \n used in regular expressions and string turns into the correct thing for the native OS.

        I suggest you whip up some code than come back for a little criticism. Oh, and always use strictures (use strict; use warnings; - see The strictures, according to Seuss) ;).

        True laziness is hard work

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://960889]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (15)
As of 2014-10-23 16:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (125 votes), past polls