i have c file and i need to add some information at the begging of the c file. I have one hash table with keys as the numbers and values as the strings. by using that table i am searching if the string found i am adding information to c file. i did this by using script i posted in ” add information to a file using perl” question. now i need to add information at the beginging of the c file if i found string.In my script i am adding before the string.
what should i do now.
thanks in advance.
i have c file and i need to add some information at the begging
Share
(Cross-posted from the answer I just gave on the SitePoint forums to what appears to be the same question.)
Sadly, there’s no way to insert information at the beginning of a file without having to rewrite the whole thing, so you’ll need to read in the entire file (rather than just one line at a time), determine which string(s) appear in the contents, write the corresponding information item(s) to a new file, and (finally!) write the original contents to the new file: