in reply to RE: Remove '.' and '..' from a list of filenames
in thread Remove '.' and '..' from a list of filenames

I didn't vote you down, but I can see perhaps why someone did. Isn't your reply incorrect? For example, if I write the following:
@vals = (".","..",".\n","..\n","foo","foo\n","bar","bar\n"); foreach (grep !/^[.]{1,2}$/,@vals) { print "$_\n"; }
It spits out:
foo foo bar bar
...as I would expect. It filtered out ".\n" and "..\n" just fine. Can you elaborate?

Replies are listed 'Best First'.
RE: RE: RE: Remove '.' and '..' from a list of filenames
by mikfire (Deacon) on Aug 23, 2000 at 00:48 UTC
    ..\n is a valid, albeit very bizarre, file name. This regex would incorrectly filter them out. I believe a more correct solution is to say /\.\.?\z/ \z is a zero width assertion that is true when you are at the actual end of the line as opposed to $, which anchors to the end of the line or possibly \n and the end of the line.

    mikfire

    A reply falls below the community's threshold of quality. You may see it by logging in.
RE: RE: RE: Remove '.' and '..' from a list of filenames
by merlyn (Sage) on Aug 23, 2000 at 00:44 UTC
    Ahh, the problem is that it filters those out when it shouldn't. Sorry, reversed logic strikes. In other words,
    /^\.$/
    matches both dot and dot-newline, and if you were expecting it to match only dot, you could be in for a big shock.

    I've edited the original note to reflect what I meant, not what I said. {grin}

    -- Randal L. Schwartz, Perl hacker