On Friday 27 February 2004 01:18, Chris generously enriched virtual reality by making up this one:
> Hi Guys, > > I have a problem with e-mail address's and an array. I have some code that > will be a documentation spider to go through all our technical > documentation, extract e-mail address's and attempt to sort and exclude > certain e-mails/patterns. All documentation is in plain text, so no > filters, etc are needed. > > The first array will have every e-mail address found pushed into it. > > The second array will be an "exclude" array, in which I would like to > search through, and remove from the "email" array, if found. > > The following code will loop through the "email" array and the "exclude" > array, and successfully removes the emails from the "email" array that are > specified in the "exclude" array: > > my %found = (); > foreach (@emails) { $found{$_}++ }; > foreach (@exclude) { exists $found{$_} and delete $found{$_} } > > BUT, if I print out the hash with this: > foreach my $key (keys %found) { > print "$key\n"; > } > > The output comes up messed up for example: > chris.com > > instead of: > [EMAIL PROTECTED] hi, this one: ---snip--- #! /usr/bin/perl use strict; use warnings; my @emails = qw/[EMAIL PROTECTED] [EMAIL PROTECTED] [EMAIL PROTECTED]/; my @exclude = qw/[EMAIL PROTECTED] [EMAIL PROTECTED] [EMAIL PROTECTED]/; my %found = (); foreach (@emails) { $found{$_}++; } foreach (@exclude) { exists $found{$_} and delete $found{$_}; } foreach my $key (keys %found) { print "$key\n"; } ---snap--- prints on my box ---snip--- #~> ./douglas_in_bloom_county.pl [EMAIL PROTECTED] [EMAIL PROTECTED] ---snap--- so I think your @emails doesnt hold what you think it does. How do you [EMAIL PROTECTED] > Why is this happening? Also, if I wanted to add for example: info without > @domain.xxx to the "exclude" array, how can I remove any e-mail in the > "emails" array based on a partial match? > You could replace foreach (@exclude) { exists $found{$_} and delete $found{$_}; } with foreach my $key (keys %found) { foreach (@exclude) { delete $found{$key} if $key=~/$_/; } } and add zappod to @exclude (no xxx). However, this takes the whole sense of using a hash in the problem so instead of looping over the keys, loop over @email and @exclude. Or someone suggests a smarter way whih I would be interested in! Wolf -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>