Edit files using the -i option. : Perl Command « Language Basics « Perl






Edit files using the -i option.

  
#!/usr/local/bin/perl -i 

while ($line = <>) { 
    while ($line =~ s#\d+\s*[*+-/]\s*\d+(\s*[*+-/]\s*\d+)*#<x>#) { 
        eval ("\$result = $&;"); 
        $line =~ s/<x>/$result/; 
    } 
    print ($line); 
} 

   
    
  








Related examples in the same category

1.A program that uses the -0 option.
2.A program that uses the -l option.
3.The -c Switch checks the Perl syntax without actually executing the Perl commands
4.The -e switch executes Perl statements at the command line instead of from a script.
5.The -n Switch: print the contents of a file or search for a line that contains a particular pattern
6.The -w option passed to the perl command generates a warning about the code itself.
7.Using -e option to execute the perl statement
8.Using /e modifier to evaluate
9.Using the -n option.
10.Using two statements with -e option
11.Using variable with -e option
12.'#!/usr/bin/perl -w ' tells the perl command to turn on extra warnings with the -w option.
13.An example of the -a option.
14.Perl can take its input from a file and send its output to a file using standard I/O redirection.
15.Executing the Script