First note: adding in the middle of a file is impossible (overwritting is possible).
Second note: In my post above I did not use $. (I did think about it though), because the OP speaks about widgets, so I guess that a widget is a special kind of line, but I can be wrong ofc...
Seek and tell in this case would be hard to use.
It would be possible to use it when the following steps are followed:
- A new temp file is created,
- The original file is opened for reading,
- File is read line by line
- If line matches the Database-string:
- Print to temp-file
- Print a fixed amount of (empty) bytes to the file, store the starting address of this data in a var (by using tell)
- Go to the previous point where empty-bytes where added (with seek) and overwrite them with the correct data.
- Jump back to the place where we were. (using seek)
- If it didn't match, check for widget etc and print to temp file.
Some remarks by this story: how much bytes should be reserved for the string?
- preferably it would be exactly the number of bytes that are needed. This could be accomplished by storing the number as an integer instead of ASCII for example,
- If too few bytes are added then vital information is overwritten,
- If too much bytes are added then the file is filled with empty data.
Using seek and tell would be possible if and only if a fixed number of bytes are added, so you can open a new (temp), write data to it while you read, add some empty bytes (which will be overriden at a later point) and do the ma
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.