First line in body of Mail::POP3Client

E

eng.john84

How to write this code if ( FIRST LINE IN BODY TRUE FOR EXAMPLE
HELLO)
{

print $_, "\n"; } please help me to wrile this code


code:


#!/usr/local/bin/perl


use Mail::pOP3Client;


$pop = new Mail::pOP3Client( USER => "xxxxxxxxx",
PASSWORD => "xxxxxxx",
HOST => "xxxxx" );


{
foreach ( $pop->Body( 1 ) ) {


if ( FIRST LINE IN BODY TRUE FOR EXAMPLE HELLO)
{


print $_, "\n";


}}}
 
E

eng.john84

I am not sure what you mean by "FIRST LINE IN BODY TRUE FOR EXAMPLE
HELLO". A line is not true or false, although what it contains may be
interpreted as indicating trueness or falseness. Do you mean that the
line contains the string "HELLO" and nonthing else? See below.



Need here:

use strict;
use warnings;













The following will print any line of message 1 that contains HELLO
anywhere (untested):

foreach ( $pop->Body(1) ) {
print "$_\n" if /HELLO/;
}

If you want the line to contain only HELLO and nothing else, then
change that to:

foreach ( $pop->Body(1) ) {
print "$_\n" if /^HELLO$/;
}

or use a string equality for efficiency:

foreach ( $pop->Body(1) ) {
print "$_\n" if $_ eq 'HELLO';
}

although in this case the line may contain a newline at the end and you
will need to either use chomp to remove or modify the test string to
"HELLO\n".

In most cases, you are better off using an explicit variable rather
than the default variable $_:

foreach my $line ( $pop->Body(1) ) {
print "$line\n" if $line eq 'HELLO';
}

Thanks your cods works great
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top