In Perl, how can I append a regex match with output from an external command in a substation?
Let's say I have a list of IPs that looks like this:
10.2.3.4
10.5.3.2 10.5.3.1 ...I know about the 'e' option in regex, which does an eval against the replacement string. I just wanted to do a straight up replacement, I could do this:
s/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/`{$1}dig -x $1 +short`/ge;
But, what I really want to do is append the host name to regex match like this:
10.2.3.4 website.example.com开发者_开发技巧
10.5.3.2 dc01.example.com 10.5.3.1 dc02.example.com ...If you all you need to do is append, you don't need a regex at all. Just do:
chomp($_ .= ' ' . qx(dig -x $_ +short)) for @list;
I'm not sure what the {$1}
is for in your example, though.
Try this, it works for me:
s/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/"$1 ". `dig -x $1 +short`/ge;
s/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/$1.`{$1}dig -x $1 +short`/ge;
精彩评论