As hippo said use the values in hash directly.
poj#!/usr/bin/perl use strict; use warnings; my $mailprog = "/usr/sbin/sendmail"; my $file = 'mailinglist.txt'; open my $fh, '<', $file or die "Could not open $file : $!"; my %mail = ( 'FROM' => 'rahul.agarwal@everyone.com', ); my $key; while (my $line = <$fh>) { if ($line =~ /^([A-Z]+)$/) { $key = $1; if ($key =~ /^END/) { undef $key; } next; } next unless defined $key; $mail{$key} //= ''; $mail{$key} .= $line; } close $fh; $mail{$_} =~ s/^\s+|\s+$//g for keys %mail; # trim #open (MAIL, "|$mailprog -t"); #print MAIL << "EOM"; print << "EOM"; To: $mail{'TO'} From: $mail{'FROM'} Subject: $mail{'SUBJECT'} $mail{'BODY'} EOM #close(MAIL);
In reply to Re^3: Parse text file data to send a mail.
by poj
in thread Parse text file data to send a mail.
by rahu_6697
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |