notasaint has asked for the wisdom of the Perl Monks concerning the following question:
I think I'm just down to the regular expression I need for finding the line in the hosts file
192.168.1.45 hostname.domain.com hostname
so it can be replaced with the new values. Unfortunately, I am bound by the modules that already exist within the Perl build on the laptops and that does not include Regex so I can't use $RE{net}{IPv4}. In the following segment of the script I have the expression to verify that there are four octets and that they are in the correct potential ranges:
if( $vmServerIP =~ m/^(\d\d?\d?)\.(\d\d?\d?)\.(\d\d?\d?)\.(\d\d?\d?)/ +){ if($1 <= 255 && $2 <= 255 && $3 <= 255 && $4 <= 255){ open (my $oldhfile, ,'<', $hfilepath) or die "Could not open $hf +ilepath for reading."; my @hfile = <$oldhfile>;
However, I'm having issues with formulating the regular expression in the foreach loop if anyone could provide me with some guidance.
foreach $hfileline (@hfile) { next unless $hfileline =~/^\s*\s+$hNames/; $hfileline = "$vmServerIP $hNames\n"; }
TIA
-nas
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: regular expression assistance
by Fletch (Bishop) on May 09, 2008 at 21:12 UTC | |
|
Re: regular expression assistance
by markkawika (Monk) on May 09, 2008 at 22:02 UTC | |
by notasaint (Novice) on May 09, 2008 at 22:14 UTC | |
|
Re: regular expression assistance
by ww (Archbishop) on May 09, 2008 at 21:12 UTC | |
by notasaint (Novice) on May 09, 2008 at 21:42 UTC | |
by ww (Archbishop) on May 09, 2008 at 21:53 UTC | |
by notasaint (Novice) on May 09, 2008 at 22:12 UTC | |
by ww (Archbishop) on May 10, 2008 at 01:16 UTC | |
|
Re: regular expression assistance
by GrandFather (Saint) on May 10, 2008 at 00:40 UTC | |
by chip (Curate) on May 10, 2008 at 00:43 UTC | |
by GrandFather (Saint) on May 10, 2008 at 01:35 UTC | |
|
Re: regular expression assistance
by carol (Beadle) on May 10, 2008 at 22:21 UTC |