I have this nagging, uncomfortable sense that I've not understood your question... but does this (simplified and not cargo-cult-able) code do what you intend?
OUTPUT:#!/usr/bin/perl use strict; use warnings; use 5.016; my @lines = ("RECORDNAME foo bar baz RECORDIP 127.2.2.1 \n", "RECORDNA +ME 1 2 3 4 5 RECORDIP 127.1.1.1\n", "RECORDNAME abcd e fgh ij RECORDI +P 127.0.0.1\n"); my $fqdn = qq/www.test.sample/; my $address = qq/nowhere_ville/; say @lines; say "-" x10 . "\n"; my @newlines = ''; for $_(@lines) { $_ =~ s/RECORDNAME/$fqdn/; #no need to /ee if your vars are sca +lars $_ =~ s/RECORDIP/$address/; push(@newlines, $_); } say @newlines;
> perl 1081659.pl RECORDNAME foo bar baz RECORDIP 127.2.2.1 RECORDNAME 1 2 3 4 5 RECORDIP 127.1.1.1 RECORDNAME abcd e fgh ij RECORDIP 127.0.0.1 ---------- www.test.sample foo bar baz nowhere_ville 127.2.2.1 www.test.sample 1 2 3 4 5 nowhere_ville 127.1.1.1 www.test.sample abcd e fgh ij nowhere_ville 127.0.0.1
If not, try re-reading your node and clarify (if you can infer it) whatever confused me. And read about quotelike operators ( perlop - scroll down to "Regexp Quote-Like Operators" and "Quote-Like Operators" ) for possibly useful information.
In reply to Re: search and replace with a variable
by ww
in thread search and replace with a variable
by tronmason
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |