Msg#: 4094316 posted 9:48 pm on Mar 9, 2010 (gmt 0)
I'd like to have a small perl script go through some files in a directory and in each file do the following, look for the first line and retrieve the time and code and then insert a line immediately after it with those two variables but in a specific format.
After have it look like: TIME=20100118095957980|EVNT=HELLO67|CODE=1234567891011121314151617|OTHERSTUFF TIME=20100118095957980|EVNT=MINNIE|CODE=1234567891011121314151617 TIME=20100118095957980|EVNT=MICKEY|NAME=MOREOTHERSTUFF
Msg#: 4094316 posted 11:58 pm on Mar 9, 2010 (gmt 0)
that should be easy enough.
look at "open" to open the file, <FILEHANDLE> (FILEHANDLE = the name you give open) to read from the file. split to parse the output. print to write to files.
since you probably don't want to mess around alot, it'd be best if you read from a file, parsed the first entry, wrote that + the next line, than read & wrote the rest of the file to a temporary file. once it's done, rename it with "rename".
look for the subroutine-names I mentioned with the command perldoc -f NAME or just ask google for "perldoc NAME".
Msg#: 4094316 posted 3:11 pm on Mar 10, 2010 (gmt 0)
You probably want to use the File::Copy module, which should have come with your distribution of perl. Check out the 'move' and 'copy' methods, they do pretty much what they sound like--move a file from one name to another (rename essentially) and copy a file from one location to another. If the destination file name exists for either, it should overwrite whatever file is there. More info with the command 'perldoc -X File::Copy move' (or copy).