in reply to Re: grab newest file
in thread grab newest file

-M is 40% faster than (stat)[9], no wonder, it does look only at modification time and doesn't build a list.
It doesn't build a list but it stores all the values from stat. From the -X man page:
If any of the file tests (or either the "stat" or "lstat" operators) are given the special filehandle consisting of a solitary underline, then the stat structure of the previous file test (or stat operator) is used, saving a system call.
So when you use -M _ or -f _ you are retrieving the stored values from the previous stat or file test.

Replies are listed 'Best First'.
Re^3: grab newest file
by shmem (Chancellor) on Jul 07, 2006 at 11:52 UTC

    Right.

    If I say (stat)[9] I am building a list containing what stat returns and reference the element with index 9 in that list. If I use -M I don't create and operate on a list (although there's an underlying structure, of course).

    Getting the right element from the underlying structure directly is faster than pulling them all out and throwing away all elements but one (even though -M involves time delta calculation).

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}