Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: extracting name & email address

by peterr (Scribe)
on Feb 23, 2015 at 08:12 UTC ( [id://1117506]=note: print w/replies, xml ) Need Help??


in reply to Re: extracting name & email address
in thread extracting name & email address

The code below has a few errors. All I want to be able to do at first, is to load an array with all the filenames after a recursive path search.
use strict; use IO::File; my $directory = '/home/******/Mail/.family.directory/Browne, Bill & Ma +rtha'; opendir(DIR,$directory); my @files = readdir(DIR); closedir(DIR); foreach(@files){ $f = new IO::File::open; while (<$f>) { //.. something here... } print $_,"\n"; }
Is this how to approach this ?

Replies are listed 'Best First'.
Re^3: extracting name & email address
by Corion (Patriarch) on Feb 23, 2015 at 08:23 UTC

    For finding all files recursively, just use File::Find.

    use File::Find; my @found_files; find( sub { push @found_files, $File::Find::name }, $directory );
      Thanks, the following lists only files, so that's a good start.
      use strict; use File::Find; my $directory = '/home/******/Mail/.family.directory/Browne, Bill & Ma +rtha'; my @found_files; find( sub { push @found_files, $File::Find::name }, $directory ); foreach(@found_files){ my $file = "$_"; if (-f $file) { print $_,"\n"; } }
      I will have to have a read up on arrays, and see how to delete certain entries from @found_files.I see that grep can be used. Possibly best to load another array with the (unwanted) filenames.
Re^3: extracting name & email address
by Anonymous Monk on Feb 23, 2015 at 08:25 UTC

    Is this how to approach this ?

    Maybe

    Consider

    Main( @ARGV ); exit( 0 ); sub Main { my @files = RecursivePathSearch( $path ); for my $file ( @files ){ SomethingHere( $file ); } } sub RecursivePathSearch { my( $path ) = @_; use File::Find::Rule qw/ find rule/ return rule( file => not_name => [ '*.pl', ], )->in( $path ); } sub SomethingHere { my( $file ) = @_; use Path::Tiny qw/ path /; use Email::Address; my $stuff = path( $file )->slurp_raw; return Email::Address->parse( $stuff ); }
      Thanks, just had to place a ";" on the 'find rule/' line. Then ran it and a msg appeared "Complex regular subexpression recursion limit (32766) exceeded at /usr/share/perl5/Email/Address.pm line 108."

      There are only 3 sub folders though in that path.

        weeel, you might try line-by-line reading of file if slurping is too much :) ... alternatively Email::Find for getting addresses

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1117506]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-04-24 09:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found