Help for this page

Select Code to Download


  1. or download this
    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 exited with error ".( $? >> 8 )."\n") if $? >> 8;
    
    chomp($num_subs);
    
  2. or download this
    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;
    
  3. or download this
    use String::ShellQuote qw( shell_quote );
    
    ...
    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;
    
  4. or download this
    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;
    
  5. or download this
    my $num_subs = 0;
    {
    ...
       local $/;
       $num_subs += s/foo/bar/g while <>;
    }