While the comments thus far have been good in having Perl discover your error, I would put forward that there's a human way as well. Whenever I write a function, I always put the following template in:
1 sub foo 2 { 4a my $self = shift; 4b my () = @_; 3 }

The numbers are the order I type the lines in. (4a is used only if I'm writing a method.) By doing this, I guarantee that I have a my () = @_; line. I suspect that if you had had that line in your code, you would've remembered to put the variable in there.

Also, I try very hard to not use the same name in a sub as I would outside the sub. There's a good reason for it, too. In a sub, you're dealing with an abstract flow, so a name like $filename or $fh is useful. Outside, you're dealing with concrete things, so names like $out_filename or $data_fh are much better. So, what you would have is

my $data_fh = IO::File->new($data_filename) || die "Cannot open '$data_filename' for reading: $!\n"; my $stuff = read_file_with_format($data_fh); ... my $second_fh = IO::File->new($second_filename) || die "Cannot open '$second_filename' for reading: $!\n"; my $other_stuff = read_file_with_format($second_fh); ... sub read_file_with_format { my ($fh) = @_; ... }

------
We are the carpenters and bricklayers of the Information Age.

The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.


In reply to Re: Improving lexical scoping outside subs by dragonchild
in thread Improving lexical scoping outside subs by toma

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.