#!/usr/bin/env perl use strict; use warnings; use Path::Tiny; ###### Output dhcp configuration file my $dhcpcdfile = 'd.conf'; # TEST my @rows = path($dhcpcdfile)->lines; my %ip_params = (); # YOU MUST POPULATE THIS FIRST my $foundinterface; # YOU MUST ASSIGN A VALUE TO THIS for my $line (@rows) { ### YOUR CODE HERE 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 } ### YOUR CODE ENDS HERE } path('spew.cfg')->spew(@rows);