Page 1 of 2

changing file contents using open function.

Posted: 30 Apr 2008, 07:34
by bin12
i was just wondering how can i change the contents of a file using open function, for example if i have this.

open(FILE, "<:utf8", "$file");
while (<FILE>);
#we read the file to find the part we want to change
close FILE;
open(FILE, ">>:utf8", "$file"); #open to print the output
print $foo #print if it doesnt exist
#how can i do the output that changes the file?
close FILE;

or can i just delete that file and write a new file instead? how? need some little assistance, sorry im still learning perl. :?

Re: changing file contents using open function.

Posted: 30 Apr 2008, 13:04
by ezza
you might wanna see this even though its a macro, the eval managed to read/edit/copy/append a text file in macro delete. Assuming the oneline eval is a small plugin inside the macro.

Re: changing file contents using open function.

Posted: 30 Apr 2008, 13:16
by sli
bin12 wrote:i was just wondering how can i change the contents of a file using open function, for example if i have this.
or can i just delete that file and write a new file instead? how? need some little assistance, sorry im still learning perl. :?

Code: Select all

open(FILE,">","$file");
Done.

Re: changing file contents using open function.

Posted: 30 Apr 2008, 20:55
by bin12
ezza wrote:bin12 wrote:
thanks for that, but its hard to read if its written in one line I'll just arrange it so it can be readable.
sli wrote:
bin12 wrote:i was just wondering how can i change the contents of a file using open function, for example if i have this.
or can i just delete that file and write a new file instead? how? need some little assistance, sorry im still learning perl. :?

Code: Select all

open(FILE,">","$file");
Done.
actually i want to delete/replace the contents of it not exactly the file, sorry if i post it the wrong way.

if i have a txt file containing this
foo bar

i want to change that to
foo foo or bar bar

Re: changing file contents using open function.

Posted: 30 Apr 2008, 23:52
by sli
Why the fuck does everything think I'm a noob? DO YOU SEE AN "UNLINK($FILE)" IN THERE ANYWHERE? BECAUSE I MUST BE BLIND. Jesus, maybe you shouldn't be a programmer.

Re: changing file contents using open function.

Posted: 01 May 2008, 00:27
by bin12
^
haha! im sorry i didnt get your post the last time. now i get it very thanks to you.. ^^

EDIT:
now it delete that part and other contents of the file. haha! ill find other solution to that

Re: changing file contents using open function.

Posted: 01 May 2008, 08:26
by sli
bin12 wrote:EDIT:
now it delete that part and other contents of the file. haha! ill find other solution to that
http://www.google.com/search?q=perl+open+file

Re: changing file contents using open function.

Posted: 01 May 2008, 11:07
by iamanoob
sli wrote:Why the fuck does everything think I'm a noob?
trisha: no you're not :?
anyways this would be useful

Re: changing file contents using open function.

Posted: 02 May 2008, 16:32
by sli
iamanoob wrote:
sli wrote:Why the fuck does everything think I'm a noob?
trisha: no you're not :?
anyways this would be useful
I almost had to answer the damn question twice until I realized I had to fucking yell about it.

Re: changing file contents using open function.

Posted: 03 May 2008, 22:56
by bin12
^
nobody tells you're a noob, what im trying to say is that you didnt get my point. im sorry if your that sensitive. :lol:

ill just store everything in array then rewrite it