Solved Find a text file value, then a preceding value

April 30, 2012 at 03:30:07
Specs: Windows 7
I have a computer game programmed in Java which exports a text file with event triggers and time stamps. I want to analyze certain parameters of gameplay with a perl script. One round of the game will look something like this:

399.359375 27814042 50
404.341797 28160978 30
404.353516 28161794 40
404.359375 28162202 140
405.410156 28235370 130
405.414063 28235642 40
405.416016 28235778 140
405.421875 28236186 130
407.447266 28377218 30
407.468750 28378714 31
411.236328 28641058 30
411.304688 28645818 32

The first two columns are a timestamp, and the third is an event trigger code. 50 marks the beginning of each round. I want to calculate trial length and inter-trial intervals (the time between the end trigger and the next 50).

I currently have a perl script which find a 50 and then runs a 'while' loop to find any of a range of 'end' triggers. This is not sufficient because the event codes can repeat a number of times in a single round, and I only want to find the LAST one.

Conceptually, I think I need the script to find a 50, and then find the next 50, and work backwards to find the other codes. Does anyone know how I would script this? Thanks in advance!!

See More: Find a text file value, then a preceding value

Report •

July 1, 2012 at 22:15:04
Not conversant with PERL. You might experiment with sorting the file (sort /r file1 > file2) then work with file2 which will be in reverse-chron order, that way your "50" "begin-session" and subsequent data will be in the order you want (your first event-code will be the last real-time occurance). This is fairly simple problem, but I'm not aquainted with PERL (yet).

Report •

July 2, 2012 at 03:03:34
✔ Best Answer
Thank you. I had not thought about reversing the entire thing. Perhaps that could work if I could wrap my mind around a script, haha.

I have since switched to MATLAB to sove this problem and I've had more luck there. In case anyone is interested, the matlab script creates a 'fifties' variable for the start triggers in column 3 and then runs on a series of 'if' statements to find the parameters I need. To find the inter-trial interval, the one I was so hung up on before, the script finds fifties(n+1) - (fifties(n+1)-1), and so on.

Report •

Related Solutions

Ask Question