Yeah, I appreciate that the removal of . and .. may not be portable to your system - I write mostly on Windows where I work which is why I just shift them off the start of the array.

Are you sure that Windows guarantees that the first two results are "." and ".."? I would not bet a cent on that. If it works, it does so by pure luck.

If you are sure, post a link to the relevant documentation from Microsoft where Microsoft guarantees that the first two results are "." and ".." (in any order), under all circumstances.

I failed to find such a statement in FindFirstFile(), FindNextFile(), and FindFirstFileEx(). Quite the opposite is true for these three functions. Microsoft clearly states that these functions return unsorted data. So if your "solution" ever worked, then only by pure luck. You are writing and propagating bad code.

but you could just add a loop to iterate over the array in the subroutine before returning the list, finding both, and deleting the elements. Wouldn't be too hard

Well, yes, but you would not loop and remove manually. grep can do that within a single line of code:

use strict; use warnings; use autodie qw( :all); opendir my $d,'/where/ever'; my @content=grep { !/^\.{1,2}$/ } readdir $d; closedir $d;

Of course, you don't need a regexp, you could also use two string compares:

use strict; use warnings; use autodie qw( :all); opendir my $d,'/where/ever'; my @content=grep { ($_ ne '.') and ($_ ne '..') } readdir $d; closedir $d;

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

In reply to Re^4: Capturing and then opening multiple files by afoken
in thread Capturing and then opening multiple files by Peter Keystrokes

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.