CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Extract Email addresses from pdf file

 



ahess
Novice

Jun 11, 2009, 6:19 AM

Post #1 of 5 (3441 views)
Extract Email addresses from pdf file Can't Post

Running ActivePerl on Windows XP and would like to extract email addresses from a pdf file and export it to a emails.csv file. Please help I've tried this script below but everytime is gives me a error Email::Valid package not installed and I just installed the package.

#!/usr/local/bin/perl -w
use strict;
# that stuff is just to make it a perl script
# email::Valid is a module to check for valid email addresses
# you can get it from CPAN.org along with tons of other modules
# If you're using perl on windows, i bet activestate has a version.
# The author says that it may be slow on Win32 if you have addresses
# where there is no nameserver to check them against.
use email::Valid;
# this loops over each line in the input
while (<>) {
# this loops over each "word" in the line (it splits on whitespace)
for my $word ( split() ) {
# if it's a valid address..
if ( my $address = email::Valid->address( $word ) ) {
# print it out.
print $address, "\n";
}
}
}


1arryb
User

Jun 11, 2009, 7:33 AM

Post #2 of 5 (3439 views)
Re: [ahess] Extract Email addresses from pdf file [In reply to] Can't Post

Hi ahess,

One problem may be that your script "uses" email::Valid, not Email::Valid. Case counts in Perl.

Cheers,

Larry


ahess
Novice

Jun 11, 2009, 11:58 PM

Post #3 of 5 (3436 views)
Re: [1arryb] Extract Email addresses from pdf file [In reply to] Can't Post

Hi 1arryb



I still get the error, "Can't locate object method address via package email::Valid (perhaps you forgot to load "email::Valid"?)

Regards


1arryb
User

Jun 14, 2009, 9:13 AM

Post #4 of 5 (3424 views)
Re: [ahess] Extract Email addresses from pdf file [In reply to] Can't Post

Hi ahess,

You forgot one. Change:

Code
if ( my $address = email::Valid->address( $word ) ) {

to

Code
if ( my $address = Email::Valid->address( $word ) ) {

and try it again.

Cheers,

Larry


KevinR
Veteran


Jun 14, 2009, 9:54 AM

Post #5 of 5 (3422 views)
Re: [1arryb] Extract Email addresses from pdf file [In reply to] Can't Post

Its a little tricky on Windows, you can actually load modules and pragmas without using the proper case, but you can't use functions/methods in the script that are incorrect case. For example this works:


Code
use STRICT; 
use WaRniNgs;
use email::Valid;
my $word = 'test@test.com';
if ( my $address = Email::Valid->address( $word ) ) {
print "$word is a valid email address";
}


Best thing though is to use the proper case all the time even when running perl on Windows.
-------------------------------------------------

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives