Replacement in a string with a function call.

Discussion in 'Perl Misc' started by K.J. 44, Nov 28, 2006.

  1. K.J. 44

    K.J. 44 Guest

    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.
     
    K.J. 44, Nov 28, 2006
    #1
    1. Advertising

  2. 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
     
    Gunnar Hjalmarsson, Nov 28, 2006
    #2
    1. Advertising

  3. 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
     
    Gunnar Hjalmarsson, Nov 28, 2006
    #3
  4. K.J. 44

    K.J. 44 Guest

    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
     
    K.J. 44, Nov 28, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mladen Adamovic
    Replies:
    0
    Views:
    777
    Mladen Adamovic
    Dec 4, 2003
  2. Mladen Adamovic
    Replies:
    3
    Views:
    14,782
    Mladen Adamovic
    Dec 5, 2003
  3. =?ISO-8859-1?Q?Martin_J=F8rgensen?=
    Replies:
    5
    Views:
    1,340
    =?ISO-8859-1?Q?Martin_J=F8rgensen?=
    May 6, 2006
  4. grbgooglefan
    Replies:
    2
    Views:
    463
    Pascal Bourguignon
    Jan 30, 2008
  5. ridcully
    Replies:
    4
    Views:
    141
Loading...

Share This Page