in reply to Re^3: Yet another config file editing programme : Tell me how to make it better !
in thread Yet another config file editing programme : Tell me how to make it better !
#!/usr/bin/perl use strict; use warnings; use Path::Tiny; ###### Output dhcp configuration file # my $dhcpcdfile = '/etc/dhcpcd.conf'; my $dhcpcdfile = 'd.conf'; # TEST ####################################### Load the output config file path($dhcpcdfile)->slurp; ### ####################################### { # block to limit scope @ARGV = $dhcpcdfile; while( my $line = <> ) { ### Is the explicit use of $line the pro +blem ??? my @ip_fields = split( /=/,$line); # look for profile with matching interface name if ( $line =~ /^\s*profile\s+static_$ip_params{interface}\b.*\n/m + ) { # format matches 'profile static_eth0' } elsif( $foundinterface and $line =~ /^.*static\s*ip_address=/ ) { $line = "static ip_address=$ip_params{'ip_address'}\n"; } elsif( $foundinterface ){ last; # No need to continue looking through the file } } ########################################### path('spew.cfg')->spew(@ARGV); ### This saves a blank file ########################################### }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Yet another config file editing programme : Tell me how to make it better !
by hippo (Archbishop) on Sep 15, 2021 at 12:38 UTC | |
by dazz (Beadle) on Sep 16, 2021 at 00:56 UTC | |
|
Re^5: Yet another config file editing programme : Tell me how to make it better !
by eyepopslikeamosquito (Archbishop) on Sep 16, 2021 at 00:58 UTC |