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
-nasIn reply to regular expression assistance by notasaint
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |