Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Perl - Regular Expressions - $value =~ s/~!/ ~!/g;?

This line is from the classic formmail.cgi script:

$value =~ s/~!/ ~!/g;

It's to stop people from using subshells. But, does anyone know what this line is actually doing and how it's doing it?

Thanks.

2 Answers

Relevance
  • 1 decade ago
    Favorite Answer

    In the Unix email reader program mailx, when you type ~! at the front of a line, it opens a subshell. Using this regex, formmail.cgi is inserting a space in front of every occurrence of tilde-bang, so that it never looks like it's at the front of a line (and therefore mailx will never open a subshell, which would be one way for someone to hack into your computer).

    Source(s): Google for mailx tilde escape
  • ?
    Lv 4
    5 years ago

    you may not do it right now. you ought to examine the record right into a string. use strict; use warnings; use record::Slurp; my $s = read_file(q{filename.txt}); $s =~ s/expression/alternative/g; write_file(q{filename.txt}, $s); __END__ or you would be able to desire to attempt the command-line arguments: perl -ibak -pe"s/expr/repl/g" filename.txt yet you have to be careful with quoting the characters in the regex, and so on.

Still have questions? Get your answers by asking now.