Help with syntax



Hi. I used perl a few years ago and found it to be wonderfully
powerful, but I don't have my old code (it's proprietary) and I seem
to have forgotten some of the subtelties of the language including how
to use references properly ... I'm using strict here to help catch
some of these subtle errors at compile time.


Anyway, can someone look at the code and tell me what the *bleep* I'm
doing wrong here?

#!/usr/bin/perl -w
use strict;

sub checkDir {
my $curDir = $_[0];
my %files = %{$_[1]};
my $file;

chdir($curDir);

my @directories;
my @listing=`ls`;
my $fileType;
my $myDir = `pwd`;

foreach $file (@listing) {
print "list: $file";
$fileType=`file $file`;
if($fileType =~ /directory/) {
print "Added to directory\n";
push @directories, $file;
}
else {
if($fileType !~ /symbolic/) {
print "regular file\n"
if(! exists $files{ $file }) { #b
my @tmpArray;
$files{ $file } = \@tmpArray;
}

push @{ $files{ $file } }, $myDir; #a

}
}
}
}

my $curDir = `pwd`;
my %files = ();

checkDir($curDir, \%files);

#end of code

The error at line labeled # a is:
"my" variable %files masks earlier declaration in same scope

The error at line labeled #b is:
syntax error

Any help would be much appreciated.

.



Relevant Pages

  • Re: When to "use strict" when teaching?
    ... >>being influenced by the history of Perl ... history bias you" essentially the same as saying you are not ... An understanding of how symbolic references work is neither necessary ... I say don't expose people to the idea of omitting "use strict" until ...
    (comp.lang.perl.misc)
  • RE: I need help here
    ... Here's the Big Secret about Perl variables that most people learn ... use strict; ... : $outputfile = shift; ... You will often see a usage message in a script which deals ...
    (perl.beginners)
  • Re: Perl Peeves
    ... the context is known at compile time. ... use strict; ... well-defined in Perl. ... number/string ambivalence of scalars. ...
    (comp.lang.perl.misc)
  • Re: newbie with a question on syntax
    ... pairs of items to the programmer (Perl doesn't care). ... The = operator** is called the assignment operator. ... if you are not using the strict pragma. ...
    (perl.beginners)
  • RE: simple references question
    ... Perl will not. ... Subject: simple references question ... If you want to alter the contents of the original array, ... Always use strict and warnings. ...
    (perl.beginners)