Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Do until connection made - need syntax help please. 1

Status
Not open for further replies.

1DMF

Programmer
Joined
Jan 18, 2005
Messages
8,795
Location
GB
Hello.

I want to execute a command (module method) and keep trying until successful as it is trying to make a connection to a mail server.

the code is as follows...
Code:
$smtp = Net::SMTP::Multipart->new("my.domain.com");

i'm a little stuck on how I make this a one liner in perl to say keep trying until successfull.

to check for unsucessful would be
Code:
    $smtp = Net::SMTP::Multipart->new("my.domain.com") or die "failed";
can i do this
Code:
until $smtp = Net::SMTP::Multipart->new("my.domain.com");

your advice is appreciated.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
Almost:
Code:
my $smtp;
1 until $smtp = Net::SMTP::Multipart->new("my.domain.com");
 
thanks ishnid, what's with the 1

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
You need to have some expression before the "until" that is to be executed on each iteration of the loop. Using "1" is basically just an expression that doesn't actually do anything. You could use any expression there. '1' is what's used most often.
 
cool thanks, a bit like the WHERE 1=1 for SQL eh?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top