in reply to Search and replace text
Like this?
my $num; while (<FILE>) { chomp; if ($. % 3 == 1) { $num = sprintf("%02d", rand(100)); substr($_, 0, 2, $num); } else { substr($_, 1, 2, $num); substr($_, -2, 2, sprintf("%02d", rand(100))); } print("$_\n"); }
If the line terminator is one character long, the above is simplifies to:
my $num; while (<FILE>) { if ($. % 3 == 1) { $num = sprintf("%02d", rand(100)); substr($_, 0, 2, $num); } else { substr($_, 1, 2, $num); substr($_, -3, 2, sprintf("%02d", rand(100))); } print; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Search and replace text
by nsyed (Novice) on Jan 27, 2006 at 04:00 UTC |