
1arryb
User
Mar 30, 2009, 5:31 PM
Post #2 of 2
(1048 views)
|
|
Re: [t_shtilman] replacement problem - please advise
[In reply to]
|
Can't Post
|
|
Hi t, I had to laugh when I saw your code. You're a bash programmer, right? So was I when I first started and this is a classic bashy mistake: Unlike bash, perl won't do command interpolation 'in-line'. You'd need two commands, like:
... my $host = `hostname`; chomp $host; s/^(MachineName=)/$1$host/; ... which would be tough to do with perl -pi -e. Easier is to define $HOST in the shell environment (it's usually already defined):
perl -pi -e "s/^(MachineName=)/$1$ENV{HOST}/;" Also, you should avoid using regex memory if you don't need it; it's slow:
perl -pi -e "s/^MachineName=/MachineName=$ENV{HOST}/;" Cheers, Larry
(This post was edited by 1arryb on Mar 30, 2009, 5:32 PM)
|