Parsing a string

Hi,
I have multiple strings like:
John, Smith can be reached at: john@microsoft.com

I have many strings like this, what I need to do is put John into $fname, Smith into $lname and john@microsoft.com into $mail.
Note this is a structure for every line: First name, Last name, text, email. Name is always first and separated by commas, email is always last.

Thanks.
MAXcomAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kim RyanIT ConsultantCommented:
$current_line =~ /^([a-z]+),\s?([a-z]+).*(\w+@\w+\.[a-z]{3}(\.[a-z]{2})?)$/i;

$fname = $1;
$lname = $2;
$mail = $3;

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MAXcomAuthor Commented:
ok i dont quite get this, lets say my line is stored in the $line, what do I do?
0
MAXcomAuthor Commented:
ok i dont quite get this, lets say my line is stored in the $line, what do I do?
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Kim RyanIT ConsultantCommented:
If you say $line =~ /^{[a-z] ... etc, you are binding the contents of $line to the regular expression. The brackets say to retain matching portions or groups. These can then be retrieved from the special verialbes, $1 for the first group etc and assigned to a local variable in your program.
0
ozoCommented:
($fname,$lname,$mail) = $line=~/(\w+)\W+(\w+).*\s(\S+)/;
0
MAXcomAuthor Commented:
Thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.