Advertisement

07.03.2008 at 01:54PM PDT, ID: 23538167
[x]
Attachment Details

Perl New Line Regular Expression

Asked by markbenham in Perl Programming Language, Regular Expressions

Tags: Perl

Hello,

I writing a Perl script that would read a file and pick out the relevant information using Perl's RegEx.
The file I'm trying to read has this in it's contents:
==========================================
Message-ID: <1214683155.4866981375524@webmail.freedom.net>
Date: Sat, 28 Jun 2008 20:59:15 +0100
From: keith@f2s.com
To: kerry@hellow.com, kbde@singtel.com,
        test@goodmail.com, test2@goodmail.com,
         test3@goodmail.com, test4@goodmail.com
Subject: test 5
MIME-Version: 1.0
Content-Type: text/plain
==========================================

I'm trying to pick out the line/s where it begins with To: by using Perl's RegEx with no success. I'm a beginner with this language and would appreciate some guidance.

This is part of my script that reads this file using a while loop:

=========================================
$gendir = "/home/vpopmail/domains/cur";
$gendest = "/home/vpopmail/domains/cur";

opendir (IN, "$gendir");
while ($f = readdir (IN) ){

        next if $f eq '.';
        next if $f eq '..';

        open (FILE, "<$gendir/$f");
        while (<FILE>) {
                if (/^To:(.*,)/) {
                        $recip = $1;
                        print $recip;
                }

                if (/^Cc:(.*),/) {
                        $recip_two = $1;
                }

                if (/^Subject:(.*)/) {
                        $subject = $1;
                }

                if (/^From:(.*)/) {
                        $from = $1;
                }

        }
        close FILE;

===========================================

I'm successful with picking the first 2 email addresses in the To: ( kerry@hellow.com, kbde@singtel.com,) field but subsequent email addresses after that doesn't seem to work.  

Can someone please assist?

Many Thanks
Start Free Trial
[+][-]07.03.2008 at 02:22PM PDT, ID: 21929213

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Perl Programming Language, Regular Expressions
Tags: Perl
Sign Up Now!
Solution Provided By: ozo
Participating Experts: 2
Solution Grade: A
 
 
[+][-]07.03.2008 at 03:05PM PDT, ID: 21929699

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.03.2008 at 03:16PM PDT, ID: 21929794

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628