Your skill will accomplish what the force of many cannot |
|
PerlMonks |
Re: Print the line with the largest number from standard input (updated)by AnomalousMonk (Archbishop) |
on Jul 22, 2019 at 14:21 UTC ( [id://11103147]=note: print w/replies, xml ) | Need Help?? |
Here's some rather excessively commented code in answer to your OPed question. One line that isn't well commented is All the caveats concerning the regex definition of a "number" noted by TieUpYourCamel here also apply. Also, I've chosen not to use chomp although others have. Why might one use or not use chomp in an application like this? I've also chosen to put the input data from your OP into a separate file and redirect the content of the file to STDIN using the < command line redirection operator. (I'm using Windows, but this should be exactly the same in *nix IIRC.) I've done this because having to re-type a bunch of test input every time you run your program is going to get very annoying very fast. A separate file is easy to edit, and multiple test files can easily be created. (Update: Of course, you can still enter input manually from the console if you wish.) Source file line_with_lagest_n_1.pl:
Update: I just noticed that the script file name is given above as line_with_lagest_n_1.pl rather than as line_with_largest_n_1.pl as I had intended. But the posted file name is the way it appears on my system, so I'm not going to bother to change it. Give a man a fish: <%-{-{-{-<
In Section
Seekers of Perl Wisdom
|
|