Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (1)
As of 2024-04-24 14:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found