Since this seems to be part of a CGI process, we have to raise the standard "issues"... You need to apply some form of file locking, because two browsers could try to make distinct changes on the same file at the same time. You probably need to include taint checking (at least), or employ some reasonably secure way of specifying the name of the file to be opened and over-written. (I've added the "easy" part: the contents of $get{post} need to be enclosed within the "quote-meta" operators \Q...\E, in case it happens to include things like period, plus, asterisk, parens, brackets, and so on, which might cause a run-time error or mis-match.)$/ = undef; $filename = "$root/content/topics/$get{'topic'}"; open( TOPIC, "+<", $filename ) or die "Unable to read/write $filename\ +n"; $_ = <TOPIC>; if( /^\Q$get{'post'}\E/ ) { s/.*\n$/$post/m; } seek( TOPIC, 0, 0 ); # rewind to start of file print TOPIC; close TOPIC;
In reply to Re: modifying a line in a file with some restrictions
by graff
in thread modifying a line in a file with some restrictions
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |