Some of the other postings give solutions that are more accessible to a beginner, but I would like to present one that demonstrates some possibilities that are available with more advanced knowledge. If the coding looks too complicated to debug and maintain, you might still be able to mine it for some ideas.

Update: based on suggestion in reply from haukex coding now does defined test instead of relying on minimum number. I realize that I have been using the technique of creating variables in a conditional (if ... defined ...) for years without really understanding it, until I came across a posting here and read through related discussion. It may be a bit more advanced than I originally thought but ok fit for the revised solution. Satisfied with the brevity of the result but wish it was less complicated. I learned from working on and revising the code, and hope at least a few readers can learn something useful as well.

#!/usr/bin/perl -n ###################################################################### # Solution requires more advanced knowledge of Perl technology # but leverages "off the shelf" technology and components # for a hopefully short and robust solution. # # -n command line switch provides loop to read file # Number parsing and max number on line come from common # Perl modules. ###################################################################### # # I am being forced to work under threat and duress # and had to remove this. Sorry. Hopefully I can put # it back some day? # # Still afraid of eviction. Harassment at every meal. # Very useful article of clothing seems to have been # stolen day I had to remove code. #

Invocation:

ron@penguin:~/monk-bus/line-w-high-no$ ./high-line.pl <in-data.txt 1 this year is 2019 1

Ron

In reply to Re: Print the line with the largest number from standard input (updated) by mr_ron
in thread Print the line with the largest number from standard input by SSSufe

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.