Multiplies every integer in a file by 2 : Escape « Regular Expression « Perl






Multiplies every integer in a file by 2

    

#!/usr/local/bin/perl 

$count = 0; 
while ($ARGV[$count] ne "") { 
   open (FILE, "$ARGV[$count]"); 
   @file = <FILE>; 
   $linenum = 0; 
   while ($file[$linenum] ne "") { 
      $file[$linenum] =~ s/\d+/$& * 2/eg; 
      $linenum++; 
   } 
   close (FILE); 
   open (FILE, ">$ARGV[$count]"); 
   print FILE (@file); 
   close (FILE); 
   $count++; 
} 

   
    
    
    
  








Related examples in the same category

1.A word-count program that handles multiple spaces and tabs between words.
2.Escape Sequences for Special Characters
3.Escape sequences, \n and \t
4.Match the new line character
5.Match multiline patterns?
6.Skip blank lines and comments