changing file contents using open function.
Moderator: Moderators
changing file contents using open function.
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.
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.
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.
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");
cs : ee : realist
Re: changing file contents using open function.
thanks for that, but its hard to read if its written in one line I'll just arrange it so it can be readable.ezza wrote:bin12 wrote:
actually i want to delete/replace the contents of it not exactly the file, sorry if i post it the wrong way.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.Done.Code: Select all
open(FILE,">","$file");
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.
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.
cs : ee : realist
Re: changing file contents using open function.
^
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
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.
http://www.google.com/search?q=perl+open+filebin12 wrote:EDIT:
now it delete that part and other contents of the file. haha! ill find other solution to that
cs : ee : realist
Re: changing file contents using open function.
trisha: no you're notsli wrote:Why the fuck does everything think I'm a noob?
anyways this would be useful
DARKest Ninja
Re: changing file contents using open function.
I almost had to answer the damn question twice until I realized I had to fucking yell about it.iamanoob wrote:trisha: no you're notsli wrote:Why the fuck does everything think I'm a noob?
anyways this would be useful
cs : ee : realist
Re: changing file contents using open function.
^
nobody tells you're a noob, what im trying to say is that you didnt get my point. im sorry if your that sensitive.
ill just store everything in array then rewrite it
nobody tells you're a noob, what im trying to say is that you didnt get my point. im sorry if your that sensitive.
ill just store everything in array then rewrite it