in reply to return $paths only if ...
use strict; use warnings; ############ 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; } } my $rar_files = dir_listing('/a/path'); if (scalar @{$rar_files}) { ###do something; print "paths defined"; } else { #do something else; print "paths not defined"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: return $paths only if ...
by cesapun (Acolyte) on Aug 20, 2012 at 17:04 UTC |