Basically, you are calling an external command, so Windows has to load up cmd.exe (dir is an inbuild command in cmd.exe as far as i know). You could very easy accomplish what you are trying to do within Perl. Doing it within perl also makes it way more portable.

If you only want the directory listing, you probably just can use glob:

#!/usr/bin/perl use strict; use warnings; my $files = [glob('*')]; print "@{$files}\n";

To learn more about glob, typing perldoc -f glob should work. If not, then your ActivePerl*\bin directory is not in your PATH. From memory: Right-clicking on Computer, Properties, Extras, Advanced and then System Variables should let you edit the PATH variables. You'll have to restart open cmd.exe windows (no windows reboot required).

Want more info about the files, like say file sizes to the file name? You could use hashes to store the data and stat to get the information. Here's a simple example:

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my @filenames = glob('*'); my %files; foreach my $fname (@filenames) { my $size = (stat($fname))[7]; $files{$fname} = $size; } print Dumper(\%files);

For more complicated things like recursive directory traversing you should take a look at CPAN modules like File::Util and/or File::Find.

But in general, i endorse people new to Perl to at least once code their own recursive finder. It's a nice learning experience and nearly everyone on PerlMonks can help you out if you get stuck.

Don't use '#ff0000':
use Acme::AutoColor; my $redcolor = RED();
All colors subject to change without notice.

In reply to Re^3: why is my reference taking a while to execute? by cavac
in thread why is my reference taking a while to execute? by perl514

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.