Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Parsing a text file to get the location of the latest

by Old_Gray_Bear (Bishop)
on Nov 03, 2012 at 02:16 UTC ( #1002070=note: print w/ replies, xml ) Need Help??


in reply to Parsing a text file to get the location of the latest

Here is how I'd do it:

  1. set newest-date to empty
  2. set this-record to empty
  3. LOOP: read a record
  4. if record is not approved, go to LOOP.
  5. if the build Date is > newest-date then move the record to this-record and set newest-date
  6. goto LOOP
What does your code look like?

Update: This code is already"Pythonized". Perhaps your meant "Haskellized"?

----
I Go Back to Sleep, Now.

OGB


Comment on Re: Parsing a text file to get the location of the latest
Re^2: Parsing a text file to get the location of the latest
by NetWallah (Monsignor) on Nov 03, 2012 at 04:47 UTC
    This one-line does the job (With your current sample data):
    perl -000 -ne '($l,$d)=m/Location:\s+(\S+).+BuildDate:\s+(\d.+\d)/s; ( +$lm,$ld)=($l,$d) if $d gt $ld and m/Approved/s}{print qq|$lm\n|' YOUR +-FILE-NAME.txt
    Note1 - the Date compare logic is very weak - it simply does a textual compare.
    Note2 - "Approved" verification is very weak.
    This is a working sample - you can use it to build a more robust program.
    Change single-quotes to double, if you use Window$.

    Update: Oops - I had intended to respond to the original post - but got OGB's post instead. Sorry.

                 "By three methods we may learn wisdom: First, by reflection, which is noblest; Second, by imitation, which is easiest; and third by experience, which is the bitterest."           -Confucius

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1002070]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (9)
As of 2014-04-16 11:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (424 votes), past polls