in reply to Re: Linux Show Permissions: traverse file access
in thread Linux Show Permissions: traverse file access

Points for pointing out that `s/// for @array` is 50% faster than `grep {} @array`.

Points for telling me about `(?s:.*)` I did not know it could be written that way. It seems to be as fast as the other method (2% slightly faster), and might be more readable.

For the third one, it comes at the prices of understanding the intention of the line code. But if I just don't use newlines, it might be better.

# perl -E '$x="abc\ndef"; $x=~s/.*/u/mi; say $x' u def # perl -E '$x="abc\ndef"; $x=~s/[\s\S]*/u/mi; say $x' u # perl -E '$x="abc\ndef"; $x=~s/(?s:.*)/u/mi; say $x' u

Will test this one in the field for a while.

Replies are listed 'Best First'.
Re^3: Linux Show Permissions: traverse file access
by jwkrahn (Abbot) on Oct 21, 2025 at 04:17 UTC
    Points for pointing out that `s/// for @array` is 50% faster than `grep {} @array`.

    You could also do all three s/// at the same time:

    s/user::/USER:$o:/, s/group::/GROUP:$g:/, s/other::/OTHER::/ for @ +A;
    For the third one, it comes at the prices of understanding the intention of the line code. But if I just don't use newlines, it might be better.

    Another way to do that which may be better:

    $P{$k} =~ tr/ \n\r\t\f/ /s; # remove newlines
    Naked blocks are fun! -- Randal L. Schwartz, Perl hacker