Hi,
I have this below issue in Perl.
I have a file in which I get list of emails as input.
I would like to parse the string before '@' of all email addresses.
(Later I will store all the string before @ in an array)
For eg. in : abcdefgh@gmail.com, i would like to parse the email
address and extract abcdefgh.
My intention is to get only the string before '@'.
Now the question is how to check it using regular expression. Or is
there any other method using substr?
while I use regular expression : $mail =~ "\@" in Perl, it's not
giving me the result.
Also, how will I find that the character '@' is in which index of the
string $mail?
I appreciate if anyone can help me out.
#! usr/bin/perl
$mail = "abcdefgh@gmail.com";
if ($mail =~ "\@" ) {
print("my name = You got it!");
}
else
{
print("my name = Try again!");
}
even $mail =~ "\@" will not work.
$mail =~ "@" will work only if the given string $mail = "abcdefgh\@gmail.com";
But in my case, i will be getting the input with email address as its.
Not with an escape character.
Thanks,
Tom
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.