Can someone explain this crazy thing?
File1 content:
2010-03-11 18:26:42,431 DEBUG 5 System 172.22.2.120 (null) asdfasd fasfdsdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf
asdf asdf asdf asdf asd fasd fasdf asdf asdf asdf as dfasdf
2010-03-11 18:26:42,431 DEBUG 9 System 172.22.2.120 (null)asdf asdf asdf asdf asdf asdf asdf asd fasdfaf as fasdf asdf asdf as df
asdf asdf adsf sdf asdf a fasdf asdf asdfdf af
2010-03-11 18:26:42,431 DEBUG 8 System 172.22.2.120 (null)asdf asdf asdf asdf asdf asdf asfasdfasf asf asdf asdf asdf
asd fasdf asdf asdf asdf asdf asdfasf asdf asdf
File2 content:
2010-03-11 18:26:42,759 8 (null) (null) (null) asdf asdf asdf asdf asfasdf asdf asdf asdf asdf asdf asdf
2010-03-11 18:26:42,759 5 (null) (null) (null) asdf as fasdf asdf asdf as fasdf asdf asdfasdf
2010-03-11 18:26:42,759 1 (null) (null) (null) asf asf asdf asdf asdfasdfasdfas df asdf
I want to read the file line by line but 1 line has to be the stuff between the dates in both files. So I thought it would be great to use $/ to make Perl read kind of line I want:
open F, $file; $/ = m/\d{4}\-\d{2}\-\d{2}\s+\d{1,2}\:\d{1,2}\:\d{1,2}/; while (<F>){# my lines go here one by one! }
It works for the first file but not for the second as when processing the second file with this code Perl treats all file as one line.
However when I change the code:
open F, $file; $/ == m/\d{4}\-\d{2}\-\d{2}\s+\d{1,2}\:\d{1,2}\:\d{1,2}/; while (<F>){# my lines go here one by one! } it works for the second file but stops for the first one (only stuff after the date in the same line is read, but nothing in consecutive lines even if this is the same date).
Is there a solution for both files? What Perl do with $/=value and $/==value ?
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.