This is some ... interesting code. You may want to consider using consistent naming conventions as well as more intuitive return types.

In your first example, you're sharing a single variable within the scope of Get_Saves, @files. In the second example you're set up to use multiple copies since you're returning @files and assigning it to another @files variable as the result of the call to find. But at the same time you're trying to pass a reference to the @files in the scope of Get_Saves. These two mechanisms are in conflict.

One version:

sub Get_Saves { my @files; @files=find(\&FileName,"/usr/local/apache/htdocs/service/"); #sure + you want to hard code this? return \@files, $#files+1; # why return the size? }##END Get_Saves sub FileName { my @files; unless (($_ eq "." )or ($_ eq "temp.svd")){ # do you need to test +for '..' too? push @files, $_; } return @files; }##END FileName

Another version:

our @files; # globally accessible sub Get_Saves { @files=find (\&FileName,"/usr/local/apache/htdocs/service/"); return \@files, $#files+1; }##END Get_Saves sub FileName { unless (($_ eq "." )or ($_ eq "temp.svd")){ push @files, $_; } }##END FileName

I don't believe that find (\&FileName(\@files)) will work because you're passing a reference to the subroutine, not invoking it.


In reply to Re: Sub in a Sub & Recursion by djantzen
in thread Sub in a Sub & Recursion by hakkr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.