james8288 has asked for the wisdom of the Perl Monks concerning the following question:

hi, i'm very new to Perl and have the following task to accomplish..

An OS command returns the following text.

SMTP-Address: [user@abc.com] [user-1@abc.com] [user-2@abc.com]
user@abc.com is the user's primary email address and the others are aliases.. We have a need to convert the mail domain from abc.com to xyz.com. And in order to convert, I need to use the following lines
SMTP-Address: [user@xyz.com] [user-1@xyz.com] [user-2@xyz.com] EOF

as input to an OS command that will modify the user's email addresses with the new xyz.com domains..

note that not every user will have 3 email addresses.. some only one, some 5, some 8,etc,etc..

all help will be greatly appreciated.

Replies are listed 'Best First'.
Re: email domain changing
by Chady (Priest) on Jul 12, 2001 at 18:12 UTC

    You should read more about this, you can solve it with what is called a RegEx as for Regular Expression:

    let's assume you know how to read the lines into an array and iterate over it, all you need to do is substitute s/// the abc into xyz:

    ex:

    while (<DATA>) { s/abc/xyz/ig; # The way this is constructed: it takes # the value in the first set of / / and # replaces it with the value in the next # set.
    Update: this could chew user abcd@abc.com, so here's a fix
    s/\@abc\.com/\@xyz\.com/ig; } __DATA__ SMTP-Address: [user@abc.com] [user-1@abc.com] [user-2@abc.com] SMTP-Address: [anotheruser@abc.com] [anotheruser-1@abc.com] [anotheruser-2@abc.com]


    He who asks will be a fool for five minutes, but he who doesn't ask will remain a fool for life.

    Chady | http://chady.net/
      A quick extension to Chady's regex.
      Just to make sure that you're only changing the domain use look ahead and look behind assertations
      Otherwise abc@abc.com would become xyz@xyz.com
      s/(?<=\@)abc(?=\.)/xyz/g
      thanks, how do I send the new email addresses as well as the old ones (we need to keep 'em for the transition period) as standard input to an OS command..