on Tue, 27 Aug 2002 16:33:42 GMT, Soheil Shaghaghi wrote:
> I am using a program that gets the user information and stores them. The
> program stores each user data in a separate file, like userid.tmp
>
> The data that is in each file looks like this:
>
> username#!#fullname#!#email#!#userid#!#registratingdate#...#!#n
Seems strange to me, storing one of info in thousands of files. Why isn't
this information stored in one file to begin with?
> What I need to do is get the e-mail addresses and the names out of these
> files and store them all in one file.
>
> I have more than 10,000 files, so I can' really do this manually.
> Is there a way to do this with Perl?
The following (untested) program could be a start
#! perl -w
use strict;
my $dir = '/development';
# Get filenames
opendir DIR, $dir or die "Cannot open '$dir': $!";
my @files = grep {/^(.*)\.tmp$/ } readdir DIR;
closedir DIR;
foreach my $f (@files) {
open FILE, $f or warn "Cannot open '$dir/$f' - skipping: $!\n";
while (<FILE>) {
if ($. > 1) {
warn "File '$dir/$f' contains more than one line!" .
" - skipping all but first\n";
last;
}
my @data = split /#!#/;
unless (@data == 6) {
warn "Illegal record structure in '$dir/$f' - skipping\n";
last;
}
print "$data[1]\t$data[2]\n";
}
close FILE;
}
__END__
username#!#fullname#!#email#!#userid#!#registratingdate#!#n
0 1 2 3 4 5
--
felix
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]