As Ln 14 is written, $line is a count of the elements in @line Processing that -- which is always a "1" as written is not quite the same as "bombs out." Precise description of the failures your code produces helps us help you.

Writing Ln 14 in any of the following fashions does PART of what you appear to intend (with respect to the FILENAME, ONLY*):

my $line = $_[0]; my $line = shift; (my $line) = @_;

The first specifies that $line should be assigned the value (content) of element zero of @_
The second does the same (cf perldoc -f shift)
The third makes the assignment in the appropriate context (qv in "Learning Perl," http://perldoc.perl.org/perldata.html#Context, Context tutorial, or any number of other places).

*However, since you seem to want to split the contents of each text file into an array of words, you'll have to do a good bit more in your sub -- namely, read the file whose name you've passed (slurping if the file is not overly large) and do the appropriate processing on that file --- all within the existing sub.


In reply to Re: Open a directory and recursively process files by ww
in thread Open a directory and recursively process files by Dr Manhattan

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.