$s =~ s!\Q$search!$replacement!g;
\Q will quote a string until \E (if \E is ommitted will quote the whole string). You need to quote the string because s/// uses regexp;
You can view more Perl written in PHP here.
$s =~ s!\Q$search!$replacement!g;
\Q will quote a string until \E (if \E is ommitted will quote the whole string). You need to quote the string because s/// uses regexp;
You can view more Perl written in PHP here.
These two Perl utility scripts are used to quickly read a text file into either a string or an array.
sub read_file_into_string {
my $s = '';
open FH, @_[0];
for (<FH>) { $s .= $_; }
close FH;
return $s;
}
sub read_file_into_array {
my @lines = ();
open FH, @_[0];
for (<FH>) {
chomp;
push @lines, $_;
}
close FH;
return @lines;
}