Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- To: John and Julie <john@example.com>, John and Julie <julie@example.com>, Bobby and Liz <bobby@example.net>, Kevin and Jayme <kevin3248@example.com>, Kevin and Jayme <jayme8396@example.com>, Ellen and Mike <mike397987@example.com>, Ellen and Mike <ellen397286@example.com>,
- >,
- #!/usr/bin/perl
- use strict;
- use warnings FATAL => 'all';
- use EmailConfig;
- use File::Slurp;
- # Turn off output buffering
- $| = 1;
- my @emailConfig = ();
- sub main() {
- loadConfig();
- processDataAndSendEmail();
- }
- main();
- sub loadConfig() {
- my @raw_configs = read_file('email_config.txt');
- foreach my $raw_config ( @raw_configs ) {
- my $newEmailConfig = new EmailConfig();
- $newEmailConfig->init($raw_config);
- push @emailConfig, $newEmailConfig;
- }
- }
- sub processDataAndSendEmail() {
- my $to = '';
- foreach my $config ( @emailConfig ) {
- foreach my $email ( @{ $config->{emails} } ) {
- print "$emailn";
- $to .= "$config->{name} <$email>, ";
- }
- }
- print "To: $to";
- }
- package EmailConfig;
- use strict;
- use warnings FATAL => 'all';
- my $emailConfigRegex = qr/(?<email_name>.*) = (?<email_addresses>.*)/;
- sub new {
- my $class = shift;
- my $self = {};
- bless $self, $class;
- return $self;
- }
- sub init {
- my $self = shift;
- my $emailConfigValue = shift;
- if ($emailConfigValue =~ $emailConfigRegex) {
- $self->{name} = $+{email_name};
- @{$self->{emails}} = split(';', $+{email_addresses});
- }
- my $print_emails = join(",", @{$self->{emails}});
- print "EmailConfig initialized: $self->{name} = $print_emailsn";
- }
- 1;
- John and Julie = john@example.com;julie@example.com
- Bobby and Liz = bobby@example.net
- Kevin and Jayme = kevin3248@example.com;jayme8396@example.com
- Ellen and Mike = mike397987@example.com;ellen397286@example.com
- sub init {
- ...
- $+{email_addresses}=~s/r//g;
- @{$self->{emails}} = split(';', $+{email_addresses});
- ...
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement