FAQ
Please help me debug this perl script, what it does is it searches a
directory for files with numbers in them and that have a desired extension,
anyway here is the script:

sub listnumfiles {
################################
# listnumfiles is (C) Copyright Charlie Somerville, and no-one else BUT
Charlie Somerville
#
# Use of listnumfiles is described in the GPL Public licence. (check
http://awstats.sourceforge.net/docs/awstats_license.html for details)
################################

my $dir,$ext,@dirlist,@retdirlist,$currfile;
$dir=$_[0];
$ext=$_[1];
if(! -d $dir) {
die "Error 2!\nPlease check the manual for an error description.\n";
}
opendir(DIR,$dir) or die "Error 1!\nPlease check the manual for an error
description.\n";
@dirlist=<DIR>;
$num=0;
foreach (@dirlist) {
if(-d $currfile) {
die "Error 3!\nPlease check the manual for an error description.\n";
}
if($currfile=~m/(\w*\d+\w*\.$ext)/) {
push @retdirlist,$currfile;
}
$num++;
}
@FILELIST=@retdirlist;
}

listnumfiles("C:/projects/test_dir/","txt");
print @listnumfile::FILELIST;

Search Discussions

  • Terrence Brannon at Feb 9, 2004 at 8:30 pm

    Charlie somerville wrote:
    Please help me debug this perl script,
    I reccommend:

    [1] use File::Find

    [2] visit www.perlmonks.org

    [3] ask on #perlhelp on IRC on efnet

    good luck

    what it does is it searches a
    directory for files with numbers in them and that have a desired extension,
    anyway here is the script:

    sub listnumfiles {
    ################################
    # listnumfiles is (C) Copyright Charlie Somerville, and no-one else BUT
    Charlie Somerville
    #
    # Use of listnumfiles is described in the GPL Public licence. (check
    http://awstats.sourceforge.net/docs/awstats_license.html for details)
    ################################

    my $dir,$ext,@dirlist,@retdirlist,$currfile;
    $dir=$_[0];
    $ext=$_[1];
    if(! -d $dir) {
    die "Error 2!\nPlease check the manual for an error description.\n";
    }
    opendir(DIR,$dir) or die "Error 1!\nPlease check the manual for an error
    description.\n";
    @dirlist=<DIR>;
    $num=0;
    foreach (@dirlist) {
    if(-d $currfile) {
    die "Error 3!\nPlease check the manual for an error description.\n";
    }
    if($currfile=~m/(\w*\d+\w*\.$ext)/) {
    push @retdirlist,$currfile;
    }
    $num++;
    }
    @FILELIST=@retdirlist;
    }

    listnumfiles("C:/projects/test_dir/","txt");
    print @listnumfile::FILELIST;



  • Brad Baxter at Feb 9, 2004 at 8:57 pm

    On Sun, 8 Feb 2004, Charlie somerville wrote:

    opendir(DIR,$dir) or die "Error 1!\nPlease check the manual for an error
    description.\n";
    Even if you have a manual, I'd include $! in that die string.
    @dirlist=<DIR>;
    perldoc -f readdir.

    Regards,

    Brad

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupscripts @
categoriesperl
postedFeb 8, '04 at 2:35a
activeFeb 9, '04 at 8:57p
posts3
users3
websiteperl.org

People

Translate

site design / logo © 2021 Grokbase