Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/perl
- use warnings;
- use strict;
- my ($i, $size, $line, @lines, $subject, $reply_address, $date, $from_name);
- $line = $subject = $reply_address = $date = $from_name = "";
- open(MYFILE, "king.in") || die("Could not open file!");
- # Read all the lines into an array
- @lines = <MYFILE>;
- close(MYFILE);
- $i = 1;
- # Iterate over the file's lines
- foreach $line (@lines) {
- if ($line =~ m/^\s+$/ ) { # If we have an empty line...
- last; # this immediately ends the 'while' loop.
- }
- if ($line =~ m/^subject: (.*)/i) {
- $subject = $1;
- }
- if ($line =~ m/^date: (.*)/i) {
- $date = $1;
- }
- if ($line =~ m/^reply-To: (\S+)/i) {
- $reply_address = $1;
- }
- if ($line =~ m/^from: (\S+) \(([^()]*)\)/i) {
- $reply_address = $1;
- $from_name = $2;
- }
- $i++;
- }
- print "To: $reply_address ($from_name)\n";
- print "From: jfriedl\@regex.info (Jeffrey Friedl)\n";
- print "Subject: Re: $subject\n";
- print "\n" ; # blank line to separate the header from message body.
- print "On $date $from_name wrote:\n";
- # print the body
- $size = @lines;
- for ($i; $i < $size; $i++) {
- print "|> $lines[$i]";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement