in reply to Search and replace in an array using data in hash

Uhm, you have quotes around the substitution. Aren't you using warnings? Perl would have warned.

BTW, I would have used different logic. You don't have to loop over the hash, just loop over the lines in the file, and do something like:

use Regexp::Common; s/($RE{net}{IPv4})/$hash{$1}/g;

Abigail

Replies are listed 'Best First'.
Re: Re: Search and replace in an array using data in hash
by halley (Prior) on Aug 08, 2003 at 15:28 UTC
    In case the hash doesn't contain the entire possible universe of domain names, you may want to offer a fall back.
    use Regexp::Common; s/ ( $RE{net}{IPv4} ) / $hash{$1} || $1 /xge;

    --
    [ e d @ h a l l e y . c c ]

      No, you don't want to do that. That makes all your substitutions slower, and it's not necessary. Remember that the files were already scanned for IP numbers, so no unknown IP numbers should be present in the file. If some IP numbers don't resolve, just put a value in the hash that's the same as the key.

      Abigail