This seems redundant, running perl from a Perl script itself.
my $Pref = "&*())(*&^%$#@!";
system("perl -pi -e 's|^SERVERNAME.*\$|SERVERNAME \"\Q$Pref\E\"|g' pserver.prefs");
What is the actual Perl code that will mimic -pi? I just want something that would work like sed on Perl, just as simple as can be.
Based on Todd Gardner's site, it seems it basically just reads and writes all of the file, attempting to apply the regex to every line. The solution was a bit complex for a noob Perl user like me, so I dumbed it down using:
my $ftp = "/home/shared/ftp";
my $backup = $ftp . ".bak";
rename($ftp, $backup);
open (FTP, "<", $backup) or die "Can't open $backup: $!";
open (FTP_OUT, ">", $ftp) or die "Can't open $ftp: $!";
while (<FTP>)
{
$_ =~ s|$panel_user \Q$panel_oldpass\E |$panel_user \Q$panel_newpass\E |g;
print FTP_OUT $_;
}
close(FTP);
close(FTP_OUT);
Is there anything wrong with using two opens? Should this be avoided or is it ok for a simple solution?
I must admit, a system sed command is much more simple and cleaner.