Hmm,

Firstly, thanks for the reply, i probably should've read up on subroutine parsing before posting, but i was blind to that apparently as it didn't even occur to me (*sigh* a post wasted on an RTFM question, sorry about that). That said, while it's true i didn't need to use a closure, this was practice. The reason for making the sub anonymous was so that only the get_init_strings subroutine could call it, which is a good intent, although admittedly completely wasted here. If i weren't so intent on using something i've never used before it would probably be closer to this (this code needs you to see where the loop happens since it's basically an orcish manuever):

# Code simplified for brevity (again) my @files = get_files(); my $strings_file = shift(@ARGV) || "default"; my @init_strings; foreach my $file (@files) { my @strings = @init_strings || get_init_strings($strings_file, \@init_strings); push @strings, extra_strings(); # manipulate files here ... } sub get_init_strings { my $file = shift; my $strings = shift; open FILE, $file or die "Couldn't open $file: $!\n"; push @$strings, $_ while <FILE>; close FILE, $file or warn "Couldn't close $file: $!\n"; return @$strings; }
This isn't tested, just the first thing that came to mind. And it would do what i did without any of the hassle. But it's not as much of a learning experience nor as fun :-)

jynx


In reply to Re: Re: Style Question on Closures by jynx
in thread Style Question on Closures by jynx

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.