perlboy has asked for the wisdom of the Perl Monks concerning the following question:

I have written a script that writes user responses into a flat file. Our networking department has recently implemented a load balancer and we now have three production boxes. The script writes into a file in a folder called /data folder and now there are three /data folders. The three files of course are not in sync. Our solution is to hard code location of the file (one of the machines has been designated as the store for the file). How do I reference a machine name (UNC) in the open() statement? I am used to something like open(HANDLE,"<$filename") but $filename pertains to a file stored in the same box as the code. Your kind response is deeply appreciated. perlboy

Edit ar0n -- title change (was "open()")

Replies are listed 'Best First'.
Re: opening a file across a network
by scain (Curate) on Aug 31, 2001 at 17:37 UTC
    I don't really think you can, unless the partition/folder is shared across the network. Is there any way you could share the file on an NFS partition or the windows equivelent?

    Scott

    Update: So you asked essentially the same question here: UNCs. Why were those answers not acceptable. If you are on windows, $code or die's answer should be enough. If you are on unix, I suspect my answer is it.

Re: opening a file across a network
by count0 (Friar) on Aug 31, 2001 at 17:48 UTC
    Well, it would be nice if it were simple. =/
    However, to my knowledge, there is no way to just modify your open()s to work like this.
    In order to get that file, you'll need to transfer it over the network through standard methods. The options that come immediately to mind are ftp or cvs (cvs would be my choice in this case). There are modules to help you with either one. Both cases would require you to get the file, modify it, and send back the new version.
    Keep in mind with using ftp, you may very well need to implement locking of some sort to keep the files in sync.

    But this is a quick-fix type solution. A brute method.
    IMO, this doesn't seem to be a situation in which load balancing is ideal. Perhaps it should be considered that only one of these servers be used to host the data file.

    In my experience, it has been more trouble than it's worth to keep mirrors of constantly changing data on seperate servers.
    Well anyway, sorry if this isn't what you were looking to hear. </my two cents>
Re (tilly) 1: opening a file across a network
by tilly (Archbishop) on Sep 01, 2001 at 07:12 UTC
    I am sorry to say it, but I think that you are going down the wrong path here.

    First of all, you have the usual problems with maintaining flatfiles. Next you need to access files on the correct machine. Then you need to handle locking, (which few people get wrong). Then you need to maintain this as it grows.

    It is a big pill to swallow, but personally I think it would be a mistake to go farther down this path. Instead I would suggest rewriting the whole thing to use a relational database.

Re: opening a file across a network
by MZSanford (Curate) on Aug 31, 2001 at 20:03 UTC
    Hmmmm, module idea ... could one not write a module which overloads open(), and checks the string for ftp://, http://, etc ... and use sub-modules to invoke LWP, Net::FTP, etc ... ? If this was done, and the file name did not being with one of these known strings, the module could use the built-in open. That would make a new 'drop-in' solution. I will write the module, but does anyone think it will be usefull ?
    can't sleep clowns will eat me
    -- MZSanford
      Yea, that seems like a good idea.
      The only catch, as I briefly stated above, is that you would (in a lot of cases) also need a modified flock()