CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions: Re: [t_shtilman] replacement problem - please advise: Edit Log



1arryb
User

Mar 30, 2009, 5:31 PM


Views: 1639
Re: [t_shtilman] replacement problem - please advise

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:

Code
... 
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):

Code
perl -pi -e "s/^(MachineName=)/$1$ENV{HOST}/;"

Also, you should avoid using regex memory if you don't need it; it's slow:

Code
perl -pi -e "s/^MachineName=/MachineName=$ENV{HOST}/;"


Cheers,

Larry


(This post was edited by 1arryb on Mar 30, 2009, 5:32 PM)


Edit Log:
Post edited by 1arryb (User) on Mar 30, 2009, 5:32 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives