in reply to Re^2: Strictly nested sub warnings
in thread Strictly nested sub warnings
You seem to be writing Perl in an idiosyncratic, verbose, almost baroque, style. To do something very simple, namely find all symbolic links under a given directory, you've got a lot of scaffolding. Perhaps the code has been taken out of context, but I feel your "input-output" parameter hash serves only to obscure the intent of the function. Good functions have few, and clearly specified, input and output. Since Perl arrays already know how many elements they contain, storing the number of elements in a separate numoLinks attribute is redundant and a violation of DRY. Anyway, FWIW, I present a shorter, more Perlish version of your subroutine:
use strict; use warnings; use File::Find; # Return a list of all symlinks found under $dir. sub SymLinkFind { my $dir = shift; my @SymLinks; find sub { -l and push @SymLinks, $File::Find::name }, $dir; return @SymLinks; } my @symlinks = SymLinkFind("."); print "Found ", scalar(@symlinks), " Symbolic Links...\n"; print "$_\n" for @symlinks;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: Strictly nested sub warnings
by raybies (Chaplain) on Oct 05, 2010 at 20:48 UTC | |
by Your Mother (Archbishop) on Oct 05, 2010 at 21:08 UTC |