Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Replacement in a string with a function call.

Reply
Thread Tools

Replacement in a string with a function call.

 
 
K.J. 44
Guest
Posts: n/a
 
      11-28-2006
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.

 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      11-28-2006
K.J. 44 wrote:
> 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

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      11-28-2006
Gunnar Hjalmarsson wrote:
> Besides that, you need the /e modifier.
>
> perldoc perlre


A more adequate pointer would be:

perldoc perlop
(the s/// operator)

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
K.J. 44
Guest
Posts: n/a
 
      11-28-2006
That worked great! THanks!

Gunnar Hjalmarsson wrote:
> Gunnar Hjalmarsson wrote:
> > Besides that, you need the /e modifier.
> >
> > perldoc perlre

>
> A more adequate pointer would be:
>
> perldoc perlop
> (the s/// operator)
>
> --
> Gunnar Hjalmarsson
> Email: http://www.gunnar.cc/cgi-bin/contact.pl


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with String.gsub and \' as a replacement string ridcully Ruby 4 11-17-2007 01:05 PM
compilation error: "error: no matching function for call to 'String::String(String)' =?ISO-8859-1?Q?Martin_J=F8rgensen?= C++ 5 05-06-2006 03:48 PM
write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter komal C++ 6 01-25-2005 11:13 AM
String.replaceAll(String regex, String replacement) question Mladen Adamovic Java 3 12-05-2003 04:20 PM
Re: String.replaceAll(String regex, String replacement) question Mladen Adamovic Java 0 12-04-2003 04:40 PM



Advertisments