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

Hi I'm an newbie to perl and i have an issue with reading mailids from text file and passing it into mailx command before the mail id were hard coded.As the number of ids have increased we are planning it read from txt file which has the id's I have the below code it works fine but i want to do it in a better way can any one help me.
Contents of pp.txt is as below. asabast@xyz.com pxpx@xyz.com jxbx@xyz.com And the out put i want is asasbast\@xyz.com pxpx\@xyz.com jxbx\@xyz.com $file = "pp.txt" ; open (FH ,$file) || die ("could not openfile"); while (<FH>) { $_ =~ s/\s+$//; s/\@/\\@/; s/.com/.com /; $line = $_; print $line; } close (FH);
Thanks in advance. Johny

Replies are listed 'Best First'.
Re: Reading mail ids from text file
by Skeeve (Parson) on Sep 18, 2007 at 06:07 UTC
    I don't get what your code shall be good for, but after reading what you wrote in the CB, I think this might help
    $file = "pp.txt"; open (FH ,$file) || die ("could not openfile"); while (<FH>) { s/[\012\015]+/ /g; s/\@/\\@/; print; } close (FH);

    s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
    +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e
Re: Reading mail ids from text file
by bruceb3 (Pilgrim) on Sep 18, 2007 at 06:18 UTC
    Looks like a job for the dynamic trio, print-join-map.
    my $file = "pp.txt" ; open (FH ,$file) || die ("could not openfile"); print join(" ", map { chomp; s/\+s$//; s/\@/\\@/; $_ } <FH> ),"\n"; close (FH);