If I have a file that looks like this:
12345: 12:34:00,890,987,9876,...
12346: 12:35:02,789,987,234,...
12344: 12:35:04,345,987,1234,...
etc.
And let's say that the 12:34:00 in line 1, 12:35:02 in line 2, and 12:35:04 in line 3 represent time. I want to separate this column for each line and do a comparison to it, keeping hours, minutes and seconds separate. I am first thinking of doing a split to separate each line by commas and then go in to each line that matches a condition '987' (for example) and for each line with '987' I want to take the time and manipulate it. This is what I have so far:
LINE: while (<THATFILE>) {
next LINE if (!/^\d+: \d{2}:/ );
foreach $field(split /,/, $line) {
chomp $field;
if ($field == '987') {
foreach $subtime (split /:/, $field) {
How do I keep each field separate so that I can determine hours, minutes, and seconds?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.