Hello perl197, and welcome to the Monastery!

Just a side note. The code:

my @file_name; while (<FH>) { push (@file_name, $_); }

can be replaced with the simpler and more idiomatic:

my @file_name = <FH>;

Here is the explanation, from readline:

In scalar context, each call reads and returns the next line until end-of-file is reached, whereupon the subsequent call returns undef. In list context, reads until end-of-file is reached and returns a list of lines.

In your code, while (<FH>) puts <FH> into scalar context1, so the while loop is needed to call <FH> repeatedly until the file is exhausted. But in the simpler version, assignment to an array variable (in this case, @file_name) puts the call to <FH> into list context, so <FH> is called only once and returns a list of all the lines in the file.

Hope this is of interest,

Update: 1Because of the implicit assignment to $_.

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,


In reply to Re: act on a file list by Athanasius
in thread act on a file list by perl197

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.