error in a subroutine

I write a Perl-script for Win32.
One of the subroutines has a mistake.

sub dateianzahl{
my $zaehler;
my $arg;

$arg=$_[0];
$zaehler=0;
foreach $arg(@arg){
 if (-d $arg){
     opendir D, $arg;
     push @arg, map{$arg.'/'.$_}
      grep {!/^(\.|\.\.)$/}readdir(D);
      closedir(d);
 if(-f $arg){
    open F, $arg;
    @l=<F>;
    close F;
    $zaehler++;
     @l=();}
 return $zaehler;}}

The subroutine is called by example
dateianzahl(c:\\u1\\hl7\\work\\ok);

What´s wrong!
Thank you for you help!
HandschuhAsked:
Who is Participating?
 
ozoConnect With a Mentor Commented:
Name "main::d" used only once: possible typo at - line 12 (#2)
   
    (W) Typographical errors often show up as unique variable names.
    If you had a good reason for having a unique name, then just mention
    it again somehow to suppress the message.  The use vars pragma is
    provided for just this purpose.

dateianzahl(c:\\u1\\hl7\\work\\ok);
Unquoted string "c" may clash with future reserved word at - line 19 (#1)
syntax error at - line 19, near "c:"

Backslash found where operator expected at - line 19, near "u1\" (#2)
   
    (S) The Perl lexer knows whether to expect a term or an operator.  If it
    sees what it knows to be a term when it was expecting to see an operator,
    it gives you this warning.  Usually it indicates that an operator or
    delimiter was omitted, such as a semicolon.
   
Also, you seem to be changing @arg inside of a loop on @arg,
0
 
olthoffCommented:
You also
opendir D $arg

but
closedir d;

I am not sure how perl handles opening another dir without closing the first one.  The d should be capitalized on the closedir...
0
 
ozoCommented:
Do you require any furthur help?
0
All Courses

From novice to tech pro — start learning today.