in reply to Getting an IP out of a string

m/(regex to match IP)/; print $1;
surround the regex to match the IP with parens, and then use the $1 variable to grab what was matched

Replies are listed 'Best First'.
RE: Re: Getting an IP out of a string
by merlyn (Sage) on Aug 16, 2000 at 22:14 UTC
    Danger will robinson!

    Never use $1 unless it's in the context of a conditional based on the success of the match. Otherwise, you get the previous success $1, and that's gonna bring you to tears while you're trying to debug it.

    -- Randal L. Schwartz, Perl hacker

      always the wise one.. :) ++merlyn
      Most people will tell you to learn from your mistakes, but I always think it's 100% better if you can learn from someone else's mistakes. This is actually one of the great reasons I visit Perlmonks -- the cooperative learning can't be beat!
      p.s. no offense intended to raflach: I might have made the same mistake.