in reply to changing a portion of a line leaving its formatting intact

If you want to match tree, but not tree2 (for example), try:
next unless /^tree[ ]/;
instead of
next unless /^tree/;

Replaces 5th field:

s/^(\S+[ ]+\S+[ ]+\S+[ ]+\S+[ ]+)(\S+[ ]+)/ my $s = int(rand($2)); $1 . $s . (' ' x (length($2) - length($s))) /e;

Update: Added missing "$1 . ", as noticed by Animator. Removed unecesary if. Tested.

Replies are listed 'Best First'.
Re^2: changing a portion of a line leaving its formatting intact
by Animator (Hermit) on Dec 14, 2004 at 19:05 UTC
    shouldn't it be $1.$s?