Replacement in a string with a function call.

K

K.J. 44

Hi,

What I want to do is search a string, find an IP Address, and replace
that with the DNS name.

$details[$i] =~ s/(\d+)(\.\d+)(\.\d+)(\.\d+):/&resolveDNS($1$2$3$4)/;

The string is named $details[$i] and resolveDNS is the function. The
function itself works. The IP Addresses I want to match are followed
by a colon and I do not want to match any other IP Addresses.

It is not making the subsitutions. It simply substitutes
&resolveDNS(IPADDRESS) instead.

Is there a way to call the function to have it return the value that i
want replaced?

Thanks.
 
G

Gunnar Hjalmarsson

K.J. 44 said:
What I want to do is search a string, find an IP Address, and replace
that with the DNS name.

$details[$i] =~ s/(\d+)(\.\d+)(\.\d+)(\.\d+):/&resolveDNS($1$2$3$4)/;
------------------------------------------------^

Why the '&'?

Why aren't you using strictures?

Besides that, you need the /e modifier.

perldoc perlre
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top