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

I have a need to create an empty lock file to notify someone when a process has run sucessfully. I have a way to do it, but am wondering if there isn't a better way to do it. Unfortunately, if there is a module out there to do this, I cannot load it onto the system since I am not the administrator.

use strict; my $process="TEST-LOCK"; open (LCK, ">"$process" . "_process_done.lck") or die "Could not creat +e $process" . "_process_done.lck $!"; print LCK "\n"; close (LCK);

"Ex libris un peut de tout"

Replies are listed 'Best First'.
Re: File Creation
by cLive ;-) (Prior) on Jun 04, 2003 at 13:52 UTC
Re: File Creation
by EvdB (Deacon) on Jun 04, 2003 at 13:58 UTC
    A couple of thoughts:

    If this is a quick and dirty then something like: system "touch $filename"; will do the trick - although make sure that you have the right filename.

    More elegantly could be acheived with a locking module, as you suggest. You can install modules yourself even if you are not the site admin. Download it off CPAN and then start using perl Makefile.PL PREFIX=/home/me/my-perl and the put use lib "/home/me/my-perl/"; at the top of you script. This will get you script to check this directory as well as the standard ones for modules.

    Also, I think you have a spare " in your open command...

    --tidiness is the memory loss of environmental mnemonics

      Since the original poster said 'administrator', and since they didn't name an operating system, I'd caution against using system("touch ..."). The touch command is not commonly available on Windows platforms. (Sure, you could install one made for Windows, but you'd have to be the administrator...)

      --
      [ e d @ h a l l e y . c c ]

      Thanks, I prefer to avoid system calls like that though, personal preference really. I think the extra " was the result of a sloppy cut-n-paste :) Still checked the actual program to make sure it hadn't snuck in there as well.

      "Ex libris un peut de tout"

Re: File Creation
by helgi (Hermit) on Jun 05, 2003 at 09:58 UTC
    Unfortunately, if there is a module out there to do this, I cannot load it onto the system since I am not the administrator.

    This is a frequently held misconception and it is refuted and answered in our trusty perl documentation under:

    perldoc -q "my own module"

    Not that you need a module in this case, but still....

    --
    Regards,
    Helgi Briem
    helgi DOT briem AT decode DOT is

Re: File Creation
by helgi (Hermit) on Jun 05, 2003 at 09:58 UTC
    Unfortunately, if there is a module out there to do this, I cannot load it onto the system since I am not the administrator.

    This is a frequently held misconception and it is refuted and answered in our trusty perl documentation under:

    perldoc -q "my own module"

    Not that you need a module in this case, but still....

    --
    Regards,
    Helgi Briem
    helgi DOT briem AT decode DOT is