Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Splitting?

by Gerard (Pilgrim)
on Dec 10, 2001 at 16:25 UTC ( #130637=perlquestion: print w/ replies, xml ) Need Help??
Gerard has asked for the wisdom of the Perl Monks concerning the following question:

I have searched for quite some time and can't seem to come up with a easy and problem free way of doing this, so any suggestions would be great. I have a list of email adresses in the form  anyone@somewhere.com, gerard@spied.co.nz, mum@work.com, albert@spied.co.nz, someonelse@hotmail.com The amount of whitespace either side of the commas is actually undertermined... it could be one none or many. Or just in the form
robert@spied.co.nz
If there is only one address. There may be spaces here also... Call me stupied if you will... but I would like to extract the user names from the email addresses at my domain (spied.co.nz). Note: There is always at least one with my domain.
It is late at night here and my brain is not functioning properly, to make matters worse, I have run out of coffee.
Would the best way to do this be to split it up on the commas, and then do something else wonderful with the array to get rid of the unwanted addresses? Please help / thoughts or other better suggestions, much appreciated. I don't expect for anyone to write the code for me, but I would love some help in getting my brain kick started. I know that this is a simple problem, but like I said, my lack of caffeine is really getting me down. Cheers, Gerard

Comment on Splitting?
Select or Download Code
Re: Splitting?
by davorg (Chancellor) on Dec 10, 2001 at 16:30 UTC
    $_ = 'anyone@somewhere.com, gerard@spied.co.nz, mum@work.com, albert@s +pied.co.nz, someonelse@hotmail.com'; my @emails; foreach (split /\s*,\s*/) { push @emails, $_ if /\@spied\.co\.nz$/; }

    Or something like that :)

    --
    <http://www.dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

      Like a charm. Cheers.
Re: Splitting?
by clemburg (Curate) on Dec 10, 2001 at 16:36 UTC

    You mean like this?

    > perl -ne 'print qq(@{[ grep /spied\.co\.nz/, split /,\s+/ ]})'

    Christian Lemburg
    Brainbench MVP for Perl
    http://www.brainbench.com

Re: Splitting?
by Anarion (Hermit) on Dec 10, 2001 at 17:40 UTC
    why not use a regex with the /g modifier,something like:
    @users=/\b(\S+)\@spied\.co\.nz/g

    $anarion=\$anarion;

    s==q^QBY_^=,$_^=$[x7,print

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://130637]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2014-12-27 15:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls