Here is how I would do it:

#!/usr/local/bin/perl -w ## ^^^^ change to your system needs. # for the best results in all your perl scripting # use strict. :) use strict; # edit these to match your needs. Remember # for dos, you will need to change the '/'s # to '\'s my $path = "/tmp"; my $file = "$ENV{HOME}/file.txt"; # open our descriptors. One for the directory # we need to read and one for the file in which # we will spool the directory information out to. opendir(DIR,$path) or die("Cannot open $path\n"); open(OP,">>$file") or die("Cannot open $file for writing\n"); # print out all files matching *.pl to file # descriptor OP (output) from reading the # DIR descriptor pointing back to $path. print OP join("\n",grep(/.*\.pl/,readdir(DIR))); # close our descriptors close(DIR); close(OP);
ADDED:
IMO, it is better to try and let the script do it all (unless you are writing a shell script (unix)or something similar) rather than calling system programs to do the work for you. It takes less machine resources to let the script (perl) do all the work for you.

For the above example, you may need to change the $path and $file variables to work for your windows machine but the rest *should* work just fine.

Edited by Snafu 1607 HRS EDT for completeness

----------
- Jim


In reply to Re: Getting the output of a shell command by snafu
in thread Getting the output of a shell command by ellem

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.