my $num_subs = `perl -w -0777 -pi -e 'my \$c=s/foo/bar/g;print STDOUT "\$c\\n"' ./foo_test`;
die("Can't execute child: $!\n" if $? == -1'
die("Child killed by signal ".( $? & 0x7F )."\n") if $? & 0x7F;
die("Child exited with error ".( $? >> 8 )."\n") if $? >> 8;
chomp($num_subs);
####
my $num_subs = `perl -i -0777wpe'print STDOUT s/foo/bar/g' foo_test`;
die("Can't execute child: $!\n" if $? == -1'
die("Child killed by signal ".( $? & 0x7F )."\n") if $? & 0x7F;
die("Child exited with error ".( $? >> 8 )."\n") if $? >> 8;
####
use String::ShellQuote qw( shell_quote );
my $cmd = shell_quote("perl", "-i", "-0777wpe", 'print STDOUT s/foo/bar/g', 'foo_test');
my $num_subs = `$cmd`;
die("Can't execute child: $!\n" if $? == -1'
die("Child killed by signal ".( $? & 0x7F )."\n") if $? & 0x7F;
die("Child exited with error ".( $? >> 8 )."\n") if $? >> 8;
####
use IPC::System::Simple qw( capturex ); # Core module
my @cmd = ( 'perl', '-i', '-0777wpe', 'print STDOUT s/foo/bar/g', 'foo_test' );
my $num_subs = capturex(@cmd);
die("Child exited with error ".( $? >> 8 )."\n") if $? >> 8;
####
my $num_subs = 0;
{
local @ARGV = "foo_test";
local $^I = "";
local $/;
$num_subs += s/foo/bar/g while <>;
}