turumkhan has asked for the wisdom of the Perl Monks concerning the following question:

Hi every body! how do i parse the directory and read the files starting with a pirticular name. like a directory of mine may contain files like:
list1 list2 listABC foo12 test2 ... and so on
so how do i read all the files starting with "list" how anyone can help me..... so thanks in advance.... - Turum

Replies are listed 'Best First'.
Re: how do i read all the files starting with a pirticular name
by Zaxo (Archbishop) on Jun 21, 2001 at 01:32 UTC

    The iteration operator in glob form, <list*> provides the file names.

    FILENAME: while (<list*>){ open(FH, "< $_") || die; FILELINE: while (<FH>) { # <> uses filehandle here, reads lines # do stuff to lines } close( FH); }
Re: how do i read all the files starting with a pirticular name
by davorg (Chancellor) on Jun 21, 2001 at 12:30 UTC
    opendir($dir) || die "Can't open $die: $!\n"; my @files = grep { /^list/ } readdir; # The files you want are now in @files