Perl Script to extract email
Having a little trouble with the below perl script
Code:
#!/usr/bin/perl |
You want lines to be an array, not a scalar:
Code:
my @lines=grep(/$string/, @buffer); |
Tried that as well but still no luck
Code:
#!/usr/bin/perl |
The grep should work, but Email::Address->parse works on strings, not arrays
Quote:
Note that the example on that page Code:
Class Methods Quote:
Incidentally, I always start Perl with 'warnings' and 'strict' turned on; highly recommend you do the same. You'll thank me later ;) Code:
#!/usr/bin/perl -w |
Thank you chrism01, I will use strict and warnings from now on.
Can you tell me How I can extract the email id's only, I wanna feed them to a database and I am actually contemplating using shell instead. |
Basically, you need to loop through the @lines array, 1 element at a time and parse that (or indeed loop through @buffer).
In your code you've already specified the Id to match on, so I don't understand your qn. Do you want addresses or Ids? |
Hi,
It will print out a line as below Code:
May 16 21:00:53 mspwss sendmail[32248]: 75E37A371C: to=leo@leog.in, ctladdr= (664/664) I want to strip the email id only from this line, I am gathering data on 550 errors and I wanna check which email ids are frequently used so I can block them |
Code:
$var1='May 16 21:00:53 mspwss sendmail[32248]: 75E37A371C: to=leo@leog.in, ctladdr= (664/664)'; HTH |
Quote:
|
You mean 32248 ?
Code:
$var1='May 16 21:00:53 mspwss sendmail[32248]: 75E37A371C: to=leo@leog.in, ctladdr= (664/664)'; |
|
Ah, the email address. The other 2 nums are email Id and the msg Id.
Code:
$var1='May 16 21:00:53 mspwss sendmail[32248]: 75E37A371C: to=leo@leog.in, ctladdr= (664/664)'; |
Thank you Chris,
I seem to be getting the below error though any idea why Use of uninitialized value $1 in concatenation (.) or string at ./email.pl line 24. Code Code:
#!/usr/bin/perl |
You need to check exactly what you're getting in each element of each of those arrays.
Try printing them to a file and have a good look; you need to know exactly what data you're dealing with before you can craft algorithms/regexes to deal with them. If you get that error, it means there wasn't a matching email addr in that string. |
Thank you Chris, I will check further
|
All times are GMT -5. The time now is 11:54 PM. |