Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8328105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:20:13+00:00 2026-06-09T01:20:13+00:00

That was a long question and I could not get it all in. But,

  • 0

That was a long question and I could not get it all in. But, I am trying to do something without MySQL here and use files. Not the preferred method but, I need to figure it out.

1 -I want to open a file of emails that are in a single column.

email1@email.com
evail2@email.com
etail3@email.com

Could be 100k lines!

2- I then want to strip the first two characters of the email and create folders.
(“e/em” “e/ev” or “e/et” per example *1(naturally if !exists))

3- Create a txt file named the two letters *1(if !exists). (path example = e/em/em.txt e/ev/ev.txt and e/et/et.txt)

4- Append those files with UNIQUE emails that start with the said first two letters.
(so, e/em/em.txt would contain email1@email.com, e/ev/ev.txt would contain evail2@email.com etc. )

I know it is nuts. But that’s what I need to do. (I am so spoiled by MySQL).

My attempt to do this was so miserable and time consuming… I just had to come here for guidance.

I am happy to install a file handling module if it would help.

*1 If it is beneficial to avoid directory and file checks every time, I would like to run a script that created all the possible folders and populate them with each folders empty files ahead of time. Creating 26 folders (a-z) each containing the 26 possible combinations (/aa /ab /ac) all containing appropriate two letter blank file created.

I need some lessons on how to do all this. Although silly, I still need to know how.

Addition:

The directories and filenames can in fact start with – or _

Still needs tweaking but thanks for the help:

#!/usr/bin/perl -w
use strict;
use warnings;
use CGI;
use CGI ':standard';
print CGI::header();
use File::Basename;
use File::Path qw/make_path/;
use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
my $path='/home/xxxx/public_html/some/directory';
my $file='1.txt';
my %EmailAddresses;
  open my $IN, '<', $path.'/'.$file or die $!;
   while (<$IN>) {
   chomp;                
   $_=~ s/\s//g;
   undef $EmailAddresses{$_};
  }
for my $EmailAddress(keys %EmailAddresses) {
 ## need to sanitize substr here for use below
  my $filename= join '/', substr($EmailAddress,0,1), substr($EmailAddress,0,2), substr($EmailAddress,0,2) . '.txt';
  $filename = $path.'/'.$filename;
  my $dir = dirname($filename);
   make_path($dir) unless -d "$dir";
     open (OUT, '>>', $filename) || die $!;
     #need to check for dupes and remove other possible issues!
     print OUT $EmailAddress, "\n";
     close OUT;
  }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T01:20:15+00:00Added an answer on June 9, 2026 at 1:20 am

    I used a hash to get the unique e-mails. You have a lot of redundant steps in your structure, though – I would remove the second level directory, its name is the same as the filename, anyway.

    #!/usr/bin/perl
    use warnings;
    use strict;
    
    my %emails;
    open my $IN, '<', '1.txt' or die $!;
    while (<$IN>) {
        chomp;
        undef $emails{$_};
    }
    
    for my $email (keys %emails) {
        open my $OUT, '>>', join '/', substr($email,0,1), substr($email,0,2),
            substr($email,0,2) . '.txt' or die $!;
        print {$OUT} $email, "\n";
    }
    

    First grouping the emails in a hash and then printing file by file is faster:

    #!/usr/bin/perl
    use warnings;
    use strict;
    
    my %emails;
    open my $IN, '<', '1.txt' or die $!;
    while (<$IN>) {
        chomp;
        undef $emails{substr($_, 0, 1)}{substr($_, 0, 2)}{$_};
    }
    
    for my $one (keys %emails) {
        for my $two (keys %{ $emails{$one} }) {
            open my $OUT, '>', join '/', $one, $two, $two . '.txt' or die $!;
            print {$OUT} "$_\n" for keys %{ $emails{$one}{$two} };
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been a long time browser here, but never have had a question that
this is a long question and weird problem that I hope to solve. My
I have a big question that has been puzzling me for a long time
I've been searching online for a long time the answer to a question that
I have a simple question. I have a long std::string that I want to
I need to make a program that adds long integers without using the biginteger
Quick question that requires a long explanation.. Say I have two tables - one
I'm not sure how long they've been doing it but I just noticed google
I have a question! I'm not sure if this is possible, but... I have
This is not so much a technical question but still part of the development

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.