| |||||||||||
| |||||||||||
modifying files.. Posted by kitwalker2886 (kitwalker2886), 21 May 2007 hi..its me again.. tell me something.. how can we modify files using perl.?? as in.. i want to open a file.. read the content and modify a part of it.. and store it back in that same file.and also.. can i create a new directory and then write to files in it from the program. i tried using mkdir,open dir n then open.. but dint work. Posted by admin (Graham Ellis), 21 May 2007 You could modify a file "in situ" if you are certain that you'll be replacing a number of bytes with exactly the same number of bytes, but otherwise you'll need to read the old file completely then writ eback to it of (if it's a big file) do a read and write loop, followed by a rename. Discs aren't like trains where you can always squeeze one more on - once yiou have 512 bytes in a secrot, you can't squeeze any more in!If you have appropriate permissions, you can create directories, files, etc, from Perl - not a problem at all. If it's not working, have a look at the special variables such as $@, $? and $! to find out why. See our more about files and advanced fiel and directory handling pages for many source code examples Posted by kitwalker2886 (kitwalker2886), 23 May 2007 yeah.. i did that reading and renaming thing that u suggested.. could u tell me a bit more bout modifying them insitu if i m sure i ll be replacing the same number of bytes.. ?? Is there a way to open a file in both read and write mode like in c++..?Posted by admin (Graham Ellis), 23 May 2007 Yes - the examples in the "advanced file handling" section I linked to in my previous post should help. This page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
|
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |