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

    you're absolutely right about the numolinks, thing.

    Though the reason it has all this scaffolding is due to the fact that the actual inlineFind function I wrote was about ten times more complex (looking for more than just symbolic links, but all sorts of different files and throwing them into an assortment of lists). So I just sorta shortened it to the symbolic link to demonstrate the warning I was getting.

    I do appreciate the pointers, however. The great thing about Perl is I can use it for years and years, and still learn a ton everyday I use it.

    Also, I admit sometimes I am a C coder at heart... well, that and I once taught assembler at a university.

    We all bear our scars. Heh.

      Also might be interesting thing to know about; File::Find::Rule.

      use File::Find::Rule; my $dir = shift || "."; print join "\n", File::Find::Rule->symlink->in($dir);