Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: changing a portion of a line leaving its formatting intact

by ikegami (Patriarch)
on Dec 14, 2004 at 16:05 UTC ( [id://414746]=note: print w/replies, xml ) Need Help??


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?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://414746]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-18 05:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found