Before answering your question, I would like to point out some areas in your code that could be improved.
sub SortDirectory() { my $arrayRef = $_[0];
You have specified an empty prototype by adding () after the subroutine name, but your subroutine actually takes an argument. Don't use prototypes unless you really need them. (In other words, leave off those parens.)
my @fileArray; my $currIndex = 0; my $i; for ( $i = 0; $i < @$arrayRef; $i++ ) { if ( (grep /\./, $$arrayRef[$i]) != "" )
grep is intended to be used for pulling elements from a list. Using grep on a scalar is silly. Additionally, you're comparing strings with the numeric comparison operator != rather than the string comparison operator ne.

This would be more Perlish: if ($arrayRef->[$i] =~ /\./)

{ $fileArray[$currIndex++] = splice(@$arrayRef,$i--,1); } } push (@$arrayRef, @fileArray); }

 

Unfortunately, your code is really just guessing as to whether each item is a file or a directory (you're clearly on a Windows machine; this /\./ test wouldn't work at all under Unix or MacOS). Instead, you should use the file test operators -d and/or -f to determine whether each item is a directory or a file:
sub SortDirectory { my($path, $arrayRef) = @_; my(@dirArray, @fileArray); foreach (@$arrayRef) { if (-d "$path/$_") { push @dirArray, $_; } else { push @fileArray, $_; } } }
Because it is necessary for the filetest operator to know where the file is, I am passing in the directory path as well as the list of contents.

In reply to Re: Using grep with wildcards by chipmunk
in thread Using grep with wildcards by Sherlock

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.