Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

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

tybalt89 showed you how to get the current date in the YYYYMMDD format you need.

use strict; use warnings; my $enddate = todate(); while(<DATA>) { last if ($. > 1 and $enddate < (split /,/)[1]); print $_; } sub todate { my ($year, $month, $day) = (localtime)[5,4,3]; return sprintf "%04d%02d%02d",$year + 1900, $month + 1, $day; } __DATA__ F12,F11,F481,F55,F989 8204B,20161002,1045.469,test,Y 8204,20170112,1064.848,test,Y 8204A,20170113,1064.505,test,Y 8204B,20170114,1045.469,test,Y

$. is a built-in variable that counts lines of input. The split function implicitly operates on the current input line, producing a list (or maybe an array), and we take a slice of that to look at the only field we care about, the date in the second column.

H:\perl>perl 1178418.pl F12,F11,F481,F55,F989 8204B,20161002,1045.469,test,Y 8204,20170112,1064.848,test,Y 8204A,20170113,1064.505,test,Y

Updated: reduced if () {last if()} to just last if().

But God demonstrates His own love toward us, in that while we were yet sinners, Christ died for us. Romans 5:8 (NASB)


In reply to Re^5: perl file formatting by GotToBTru
in thread perl file formatting by perlforsgs

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 an uproarious good time at the Monastery: (2)
As of 2024-04-26 02:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found