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

hello Monks, I am trying to grep for the .tdt file under a dirctory and store them in $TDT so I can call the $TDT later : I am doing the following :
chdir "c:/tdt/src"; opendir TDT; for my $TDT( grep { /\.tdt/ } readdir( TDT )) { system ("$BASEDIR/nbsstools/tdtgen/bin/tdtgen $TDT"); }
the tdtgen is an excutable, now the problem is , it seems not to catch the .tdt files when I do the grep for them , I tried also
for my $TDT (`ls -l *.tdt`)
but both techniqes don't seem to work , do you see the problem there , thanks

Replies are listed 'Best First'.
Re: match names
by DamnDirtyApe (Curate) on Aug 07, 2002 at 21:41 UTC

    I believe opendir requires a directory argument. Try reducing the first two lines to:

    opendir TDT, "c:/tdt/src" ;

    _______________
    DamnDirtyApe
    Those who know that they are profound strive for clarity. Those who
    would like to seem profound to the crowd strive for obscurity.
                --Friedrich Nietzsche
Re: match names
by Jaap (Curate) on Aug 07, 2002 at 22:58 UTC
    To me, chdir is just Bad (notice the capital 'B').
    How about something like
    my $tdtRoot = 'c:/tdt/src'; if (opendir (DIR, $tdtRoot)) { while (my $fileName = readdir (DIR)) { if ($fileName =~ m/\.tdt$/) { system ("$BASEDIR/nbsstools/tdtgen/bin/tdtgen $tdtRoot/$fileName +"); } } closedir (DIR); }
Re: Find Files in Directory Matching Pattern
by tadman (Prior) on Aug 07, 2002 at 22:27 UTC
    You're on the right track. How about this?
    chdir("c:/tdt/src") || die "trying"; # Or whatever works foreach my $tdt (<*.tdt>) { system("$BASEDIR/nbsstools/tdtgen/bin/tdtgen", $tdt); }
    This uses the glob feature. By the way, make sure your chdir call succeeds.

    As a note, your test /\.tdt/ is equivalent to *.tdt* which means that foo.tdt.txt will also match.
Re: match names
by abitkin (Monk) on Aug 07, 2002 at 21:39 UTC
    It looks like you're using cygwin. If so c:/ will not work, you need /cygdrive/c/tdt/src