conflicting errors
- From: cspears2002@xxxxxxxxx (Chris)
- Date: Tue, 28 Aug 2007 21:19:31 -0700
I'm writing a script that maps out a file system. Here is what I have
so far:
#!/usr/bin/perl -w
use strict;
#use Data::Dumper;
sub data_for_path {
my $path = shift;
if (-f $path or -l $path) {
return undef;
}
if (-d $path) {
my %directory;
opendir PATH, $path or die "Cannot opendir $path: $!";
my @names = readdir PATH;
closedir PATH;
for my $name (@names) {
next if $name eq '.' or $name eq '..';
$directory{$name} = data_for_path("$path/$name");
}
return \%directory;
}
warn "$path is neither a file nor a directory\n";
return undef;
}
#print Dumper(data_for_path(".."));
my $filesystem_ref = data_for_path("..")
foreach (keys %$filesystem_ref) {
if ( $filesystem_ref->[$_] = undef) {
print $_."\n";
}
}
If I run the script, I get the following error messages:
Global symbol "$filesystem_ref" requires explicit package name at
filesystem.pl line 30.
syntax error at filesystem.pl line 30, near ") {"
Global symbol "$filesystem_ref" requires explicit package name at
filesystem.pl line 31.
Execution of filesystem.pl aborted due to compilation errors.
However if I put a 'my' in front of $filesystem_ref at the line
numbers indicated in the error message, I get the following error
message:
"my" variable $filesystem_ref masks earlier declaration in same
statement at filesystem.pl line 30.
"my" variable $filesystem_ref masks earlier declaration in same
statement at filesystem.pl line 31.
Can't declare hash dereference in my at filesystem.pl line 30, near
"$filesystem_ref) "
syntax error at filesystem.pl line 30, near ") {"
Can't use global $_ in "my" at filesystem.pl line 31, near "[$_"
Execution of filesystem.pl aborted due to compilation errors.
Now I'm just confused. What's up with these conflicting error
messages?
.
- Follow-Ups:
- Re: conflicting errors
- From: John W. Krahn
- Re: conflicting errors
- From: Yitzle
- Re: conflicting errors
- Prev by Date: Re: Doubt on Pattern Matching
- Next by Date: Re: conflicting errors
- Previous by thread: how to modify a variable stored in a hash value
- Next by thread: Re: conflicting errors
- Index(es):
Relevant Pages
|