Results 1 to 4 of 4

Thread: Searching directory (Perl)

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2000
    Posts
    225

    Searching directory (Perl)

    Hiyas,

    How do I search a directory (let's call it '/asdf' to set things straight ) for all ".txt" files using CGI/Perl? The directory is a subdirectory of the directory where the CGI/Perl script is located. I want the results (the results being the filenames of all ".txt" files in the '/asdf' directory) stored in an array. I can't figure this out... Can anyone help?

    Thanks in advance,

    -Git
    Last edited by git; Feb 21st, 2003 at 05:41 AM.

  2. #2
    Member
    Join Date
    Jan 2003
    Posts
    44
    Code:
    chdir 'asdf' or die $!;
    my @file_names = glob '*.txt';

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jul 2000
    Posts
    225
    Cool - thanks for that!

    BTW, one more (and hopefully final) question about Perl... How do I delete the entire contents of an array, aka remove all the array's elements?

    Thanks again,

    -Git

  4. #4
    Member
    Join Date
    Jan 2003
    Posts
    44
    There are many different ways, the simplest being to just assign an empty list. But these all do the same thing.
    Code:
    @a = ();
    $#a = -1;
    undef @a;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width