
relroy
Novice
Apr 15, 2010, 6:14 PM
Post #1 of 10
(646 views)
|
|
Reading contents of all files in a directory
|
Can't Post
|
|
I have a directory with 1000 files which contain email msgs (1 file is attached as sample). Aim is to extract the IP addresses from the received headers of the messages and extract domains from the body of the messages to give sample output as below:- File: filename2 IP: 12.2.3.40 Domain: domain2.com Domain: domain3.com Current code gives the filenames but isnt extracting IP address from the files, says uninitialized $_ ----------------------------------------------------------- #!C:/strawberry/perl/bin/perl #directory.plx use strict; use warnings; chdir("C:/Documents and Settings/Administrator/Directory101") or die "$!"; opendir (DIR, ".") or die "$!"; my @files = readdir DIR; close DIR; local @ARGV = @files; foreach $ARGV (sort @ARGV) { print "Filename: $ARGV \n"; if (m /^d(,3)\.\d(1,3)\.\d(1,3)\.\d(1,3)\$/) { print "IP Address: $_ \n"; } } Any tips would be welcome. Thank you!
(This post was edited by relroy on Apr 15, 2010, 6:27 PM)
|