Please read Writeup Formatting Tips - in particular, surrounding your code with <code> tags will make it dramatically more legible. In the future, you should also include your output and a better description of your problem - saying "but it does not work" is usually frowned upon since there are many ways a code can "not work".

In your code, note that the line $recent = (stat(_))[9]; is missing a sigil in front of $_ - you mean $recent = (stat($_))[9];. The big problem you are encountering is likely that you are not testing your file name in your plus_recent subroutine to see if the file is a log file - you are locating the most recent file in your entire directory tree (after the $_ fix).

Note also in your commented open line you should likely use or in place of || - see Operator Precedence and Associativity.

Update: Learned something new re: stat. Thanks Bloodnok.


In reply to Re^3: Find most recently file by kennethk
in thread Find most recently file by clementine

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.