cesapun has asked for the wisdom of the Perl Monks concerning the following question:
Hellooo
I have a problem/question.I have this code(just a part ):
############ SCAN DIRECTORY SUBROUTRINE #################### { my @paths; sub dir_listing { my ($root) = @_; $root .= '/' unless $root =~ /\/$/; for my $f (glob "$root*"){ push @{$paths}, $f if $f =~ m/\.rar$/; dir_listing($f) if -d $f; } return $paths; } }
and the problem is that "return" is defined even if directory does not contain any .rar files.
To check if subroutine returned any paths i use:
if (defined $paths){ ###do something; print "paths defined"; } else{ #do something else; print "paths not defined"; }
When i run the script,all i get is "paths defined" even if my directory does not contain rar files.
Help ~! :(
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: return $paths only if ...
by toolic (Bishop) on Aug 20, 2012 at 14:44 UTC | |
| |
|
Re: return $paths only if ...
by Anonymous Monk on Aug 20, 2012 at 15:23 UTC | |
by cesapun (Acolyte) on Aug 20, 2012 at 17:04 UTC | |
|
Re: return $paths only if ...
by aitap (Curate) on Aug 20, 2012 at 15:18 UTC | |
by chromatic (Archbishop) on Aug 20, 2012 at 16:33 UTC |