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

This may be more of a unix question than perl question, but here goes. I have two different programs that do the same thing,
$mod = `ls -l $db`;
In one program, I get for $mod:
-rw-r--r-- 1 hroberts 36761119 May 30 01:07 /usr/ncbi/blast/db/temp_ +big/patntdir/patnt.nsq
while in another I get:
-rw-r--r-- 1 hroberts staff 36761119 May 30 01:07 /usr/ncbi/blast +/db/temp_big/patntdir/patnt.nsq
Both programs are run as the same user. How in the world does one program get the field for group ownership (staff), and not the other??? This is on Solaris 2.6.

Replies are listed 'Best First'.
Re: Inconsistent ls -l results??
by ZZamboni (Curate) on Jun 14, 2001 at 22:19 UTC
    Solaris comes with two versions of ls: the BSD version in /usr/ucb/ls, and the SystemV version in /usr/bin/ls. And it turns out that the -g flag has opposite effects. On the BSD version, -g makes it show the group of the file (which is not shown by default), whereas in the System V version, the group is shown by default, and -g hides it.

    So the problem must be that your programs are using different paths, so they end up executing the different versions of ls.


      That sounds good. I don't use stat because stat returns only epochal time, and I would have to import an extra module to re-parse that into human-comprehensible calendrical time.
        Not true. localtime($epoch_time) will return an array with all the time components. And scalar(localtime($epoch_time)) will even give you a nicely formatted string.


Re: Inconsistent ls -l results??
by Beatnik (Parson) on Jun 14, 2001 at 21:49 UTC
    This might be more of a Perl answer than a UNIX one, but...

    Why not use Perls functionality to check file statistics?? stat is very good at that. Using shell calls for something like that is just plain silly, not to mention insecure.

    Update: ofcourse readdir and glob can be (ab)used for reading the directory's contents.

    ... Quidquid perl dictum sit, altum viditur.
(tye)Re: Inconsistent ls -l results??
by tye (Sage) on Jun 14, 2001 at 21:55 UTC

    Some versions of Unix require "ls -lg" to get the group owner of files listed. The solution? Use Perl's stat as already suggested.

            - tye (but my friends call me "Tye")
Re: Inconsistent ls -l results??
by premchai21 (Curate) on Jun 14, 2001 at 21:49 UTC
    Have you checked $db? Have you tested several times to see if something strange happened between runs?