changing file contents using open function.

Forum closed. All further discussion to be discussed at https://github.com/OpenKore/

Moderator: Moderators

Message
Author
bin12
Noob
Noob
Posts: 5
Joined: 30 Apr 2008, 07:06

changing file contents using open function.

#1 Post 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. :?

ezza
Developers
Developers
Posts: 109
Joined: 04 Apr 2008, 09:50

Re: changing file contents using open function.

#2 Post 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.

sli
Perl Monk
Perl Monk
Posts: 810
Joined: 04 Apr 2008, 17:26
Noob?: No

Re: changing file contents using open function.

#3 Post 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.
cs : ee : realist

bin12
Noob
Noob
Posts: 5
Joined: 30 Apr 2008, 07:06

Re: changing file contents using open function.

#4 Post 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

sli
Perl Monk
Perl Monk
Posts: 810
Joined: 04 Apr 2008, 17:26
Noob?: No

Re: changing file contents using open function.

#5 Post 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.
cs : ee : realist

bin12
Noob
Noob
Posts: 5
Joined: 30 Apr 2008, 07:06

Re: changing file contents using open function.

#6 Post 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

sli
Perl Monk
Perl Monk
Posts: 810
Joined: 04 Apr 2008, 17:26
Noob?: No

Re: changing file contents using open function.

#7 Post 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
cs : ee : realist

iamanoob
Plain Yogurt
Plain Yogurt
Posts: 82
Joined: 04 Apr 2008, 09:49

Re: changing file contents using open function.

#8 Post by iamanoob »

sli wrote:Why the fuck does everything think I'm a noob?
trisha: no you're not :?
anyways this would be useful
Image
DARKest Ninja

sli
Perl Monk
Perl Monk
Posts: 810
Joined: 04 Apr 2008, 17:26
Noob?: No

Re: changing file contents using open function.

#9 Post 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.
cs : ee : realist

bin12
Noob
Noob
Posts: 5
Joined: 30 Apr 2008, 07:06

Re: changing file contents using open function.

#10 Post 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

Locked