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