Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
If I start this on Linux (#!/usr/bin/perl use strict; use warnings; our $| = 1; my $host_name = "test_host"; my $host_ip = "192.168.0.50"; #my $hosts = 'C:\Windows\System32\drivers\etc\hosts'; my $hosts = '/etc/hosts'; unless (defined gethostbyname $host_name) { print "Cannot find \"$host_name\"\n"; print "Adding $host_name to $hosts ... "; open my $fh, ">>", $hosts or die "Cannot open \"$hosts\" for a +ppending: $!\n"; print $fh "$host_ip\t$host_name\n"; close $fh; print "OK\n"; print "Checking if $host_name is known now\n"; my $packed_ip = gethostbyname $host_name || 0; print "--- $packed_ip ---\n"; }
) it does not work:SUSE Linux Enterprise Server 10 (x86_64) VERSION = 10 PATCHLEVEL = 4 perl -v This is perl, v5.8.6 built for i686-linux
Can anyone explain why and is there any workaround? Thanks, Vadim# /tmp/gethostbyname.pl Cannot find "test_host" Adding test_host to /etc/hosts ... OK Checking if test_host is known now --- 0 --- #
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: /etc/hosts is not evaluated after modification on Linux
by Corion (Patriarch) on May 30, 2015 at 16:56 UTC | |
|
Re: /etc/hosts is not evaluated after modification on Linux
by philipbailey (Curate) on May 30, 2015 at 21:11 UTC | |
by Anonymous Monk on May 31, 2015 at 06:22 UTC | |
|
Re: /etc/hosts is not evaluated after modification on Linux
by afoken (Chancellor) on May 31, 2015 at 06:44 UTC | |
by Anonymous Monk on May 31, 2015 at 09:02 UTC | |
|
Re: /etc/hosts is not evaluated after modification on Linux
by vinoth.ree (Monsignor) on May 30, 2015 at 17:36 UTC | |
|
Re: /etc/hosts is not evaluated after modification on Linux
by Anonymous Monk on May 31, 2015 at 05:33 UTC |