Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

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

by ikegami (Pope)
on Dec 14, 2004 at 16:05 UTC ( #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
Node Status?
node history
Node Type: note [id://414746]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2020-10-22 21:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (230 votes). Check out past polls.

    Notices?