Chad Eldridge wrote: > Rob Dixon wrote: >> Chad Eldridge wrote: >> > >>> Mathew wrote: >> >> >>>> Adriano Ferreira wrote: >> >>> >>>>> On 2/2/07, Mathew Snyder <[EMAIL PROTECTED]> wrote: >> >>>> >>>>>> I have a script which extracts email addresses from a web page, >>>>>> pushes them into an array and then prints them out before asking >>>>>> if I wish to >>>>>> perform the work on them that is required. >>>>>> >>>>>> What I would like to do is compare the username portion of the >>>>>> email address to a list of usernames in a hash to determine if the >>>>>> email >>>>>> address should be skipped. I just don't know how to write out the >>>>>> regex >>>>>> for that. The line I have so far is >> >>>> >>>>>> push @emails, $email if $email =~ m/[EMAIL PROTECTED]/gmx unless ($email >>>>>> =~ m/^ >>>>>> >>>>>> I don't know how to further this to accomplish what I need. Can >>>>>> someone please >>>>>> help. >> >>> >>>>> Be lazy. Use Email::Address to take care of the parsing of the e-mail >>>>> addresses and many subtleties in the specification you even didn't >>>>> want to know about. >>>>> >>>>> use Email::Address; >>>>> my $addr = Email::Address->new(undef, '[EMAIL PROTECTED]'); >>>>> my $user = $addr->user; # this is "casey" >> >> >> >> I'm hesitant to bring another module into this. I don't want to >> make it >> >> any more complicated than it needs to be. >> > >> > I usually try and use as few modules as possible as well, >> especially for >> > simple tasks. >> >> Why? >> >> > I would suggest something like this maybe... >> > >> > Assuming %Skip is your hash of users to skip over... >> > >> > my ($user) = ($email =~ /[EMAIL PROTECTED]/); >> >> That will put either 1 or undef into $user, depending on whether the >> contents of >> $email match the regex. I assume you meant >> >> my ($user) = ($email =~ /(.+?)[EMAIL PROTECTED]/); >> >> which would put the part of the email up to the 'at' sign into $user. But >> there's no need to match anything after the at, so you could write >> >> my ($user) = ($email =~ /(.+?)\@/); >> >> or just >> >> my ($user) = $email =~ /([EMAIL PROTECTED])/; >> >> > unless ($Skip{$user}) { >> > push(@emails,$email); >> > } >> >> But using Email::Address would have got it right in the first place, >> and I still >> can't see what the disadvantage is. >> >> HTH, >> >> Rob > > You are right about that code I posted, I'm sorry about that. I was > thrown together in a hurry while doing several things at once. I guess I > should take more time when trying to help someone. > > As to disadvantages to Email::Address, I can't see any. It's not a > matter of disadvantage, I just prefer to write the code myself when I > can. Mostly this comes just from curiousity. So, it's really more > preference than a matter of advantage. I'm not going to try and re-write > Net::SMTP or anything. > > Chad >
I agree with the curiosity. Plus what better way to learn than doing it for one's self first. Mathew -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/