explor wrote:
Hi Gurus,

Hello,

I am new to perl and need some help to learn regex in perl. From the
below line i need to extract following:

Part I
1) $ENVFROM = dapi...@testhost.com
2) $ENVTO1 = te...@etc.com
3) $ENVTO2 = te...@etc.com
4) $ENVTO3 = samt...@abc.com


line=EnvFrom: dapi...@testhost.com, HdrTo: <davis....@test.com>,
EnvTo: avis....@test.com, te...@etc.com, samt...@abc.com, Subject:
TEST for perl

$ perl -le'
my $x = q[line=EnvFrom: dapi...@testhost.com, HdrTo: <davis....@test.com>, EnvTo: avis....@test.com, te...@etc.com, samt...@abc.com, Subject: TEST for perl];

my @fields = split /(\w+):\s+/, $x;

my %data;
for ( my $index = 0; $index <= $#fields; ++$index ) {
    if ( $fields[ $index ] =~ /\Aenv(?:from|to)\z/i ) {
push @{ $data{ uc $fields[ $index ] } }, split /\s*,\s*/, $fields[ ++$index ];
        }
    }

use Data::Dumper;
print Dumper \%data;
'
$VAR1 = {
          'ENVFROM' => [
                         'dapi...@testhost.com'
                       ],
          'ENVTO' => [
                       'avis....@test.com',
                       'te...@etc.com',
                       'samt...@abc.com'
                     ]
        };



John
--
Those people who think they know everything are a great
annoyance to those of us who do.        -- Isaac Asimov

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to