wanderer has asked for the wisdom of the Perl Monks concerning the following question:
This program prints the IP address but not the host name ($2) as defined( I thought) by the second set of parentheses (${$HN})-- Without the ${$HN} NO match is made at all. I know I already have the hostname ($HN) but dont understand why $2 is not set to $HN The format of the hosts file(or at least the entries I am interested in) is as follows#!/usr/bin/perl my $HN = `hostname`; my $hosts =`cat /etc/hosts`; if ( $hosts =~ /^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\s+(${$HN})\s/g ) { print "$1\n"; print "$2\n"; }
Can you explain a) why $2 is not populated and b) why just supplying ($HN) instead of (${$HN}) does not workx.y.z.22 fred<space or tab>localhost x.y.z.23 fred-test-0 x.y.z.24 fred-test-1
|
---|