struggling to conquer a split/reg. expression issue with records in a flat file
Posted on 2003-03-11
I have a flat file database that contains records in the following format:
Date/Time of post attempt: Tue Mar 11 11:34:41 2003
IP Address: 0.0.0.0
Browser: Mozilla/4.0 (compatible; MSIE 5.01;)
Error Message: Missing data. Please ensure you have entered a message.
The above is ONE single record, on mutiple lines of the file. Each record is written exactly as above on a new line each time. What I would like to do in my display script, is "massage" the display so that each record is displayed as fields on a single line, not multiple lines. Somewhat like below:
Message Date/Time IP Browser Error
UNSUCCESSFUL POST! Tue Mar 11 11:34:41 2003 0.0.0.0 Mozilla/4.0 (compatible; MSIE 5.01)
I have tried multiple ways to split on the newline character and cannot fathom it. For example:
$row = $_; # this reads in the whole file
@fields = split (/\n/, $row); # trying to split on newline
$fields[$i] =~ s/\n/ /g; # also tried substituting newline with whitespace.
Each time, it just displays the record on mutiple lines. I can change the file writing routines to write the records differently so that it is continuous records, delimited by a special character for instance, and I will do that if needs must but i'd like to be able to look at the flat file in a relatively pleasing format as well as display it for all my "users" like I stated above. If anyone could help out, that would be much apreciated.