in reply to Re: Replacing an entire line if a substring is found
in thread Replacing an entire line if a substring is found
While you made good points i suspect this is more what he was after
Resultuse strict; use warnings; use feature 'say'; while ( my $line = <DATA> ) { chomp $line; say replace( $line, 'SUBSTR', 'FOO' ); } sub replace { my ( $input, $wanted, $replacement ) = @_; if ($input =~ m/$wanted/) { return $replacement;} else { return $input; } } __DATA__ path/to/some/file path/to/some/other/file path/to/SUBSTR/file #replace entire line if SUBSTRING is found path/to/file
path/to/some/file path/to/some/other/file FOO path/to/file
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Replacing an entire line if a substring is found
by 1nickt (Canon) on Apr 26, 2017 at 03:27 UTC | |
by huck (Prior) on Apr 26, 2017 at 03:32 UTC | |
|
Re^3: Replacing an entire line if a substring is found
by victorz22 (Sexton) on Apr 26, 2017 at 06:11 UTC | |
by huck (Prior) on Apr 26, 2017 at 06:56 UTC | |
by 1nickt (Canon) on Apr 26, 2017 at 15:23 UTC |