Re: Problem with unless statement

2012-04-28 Thread sono-io
On Apr 28, 2012, Shawn H Corey wrote: > Moral of the story: use meaningful variable names. Yep, you're right. =:\ I thought it was going to be a simple question about the unless statement. Turns out I was headed down the wrong path, so I changed the variable name to make it clear. Ne

Re: Problem with unless statement

2012-04-28 Thread Uri Guttman
On 04/28/2012 01:28 PM, Shawn H Corey wrote: On 12-04-28 12:36 PM, Uri Guttman wrote: that reduces to just: my $host = $mail_field || 'localhost' ; which is the classic defaulting style. it has one flaw, it makes '' and 0 not allowed for values in $mail_field. but i doubt those would ever be g

Re: Problem with unless statement

2012-04-28 Thread Shawn H Corey
On 12-04-28 12:36 PM, Uri Guttman wrote: that reduces to just: my $host = $mail_field || 'localhost' ; which is the classic defaulting style. it has one flaw, it makes '' and 0 not allowed for values in $mail_field. but i doubt those would ever be good host names so it should be fine here. you

Re: Problem with unless statement

2012-04-28 Thread Uri Guttman
On 04/28/2012 12:10 PM, Jim Gibson wrote: On Apr 28, 2012, at 9:04 AM, sono...@fannullone.us wrote: my $host = 'localhost'; if ( defined ($mail_field) and ($mail_field ne '') ) { $host = $mail_field; } I would use: my $host = $mail_field ? $mail_field : 'localhost' ; that reduces

Re: Problem with unless statement

2012-04-28 Thread Michael Rasmussen
On Sat, Apr 28, 2012 at 12:16:57PM -0400, Shawn H Corey wrote: > On 12-04-28 12:10 PM, Jim Gibson wrote: >> >> On Apr 28, 2012, at 9:04 AM, sono...@fannullone.us wrote: >> >>> my $host = 'localhost'; >>> >>> if ( defined ($mail_field) and ($mail_field ne '') ) { >>> $host = $mail_field; >>> } >

Re: Problem with unless statement

2012-04-28 Thread Shawn H Corey
On 12-04-28 12:10 PM, Jim Gibson wrote: On Apr 28, 2012, at 9:04 AM, sono...@fannullone.us wrote: my $host = 'localhost'; if ( defined ($mail_field) and ($mail_field ne '') ) { $host = $mail_field; } I would use: my $host = $mail_field ? $mail_field : 'localhost' ; Well, since

Re: Problem with unless statement

2012-04-28 Thread Jim Gibson
On Apr 28, 2012, at 9:04 AM, sono...@fannullone.us wrote: > my $host = 'localhost'; > > if ( defined ($mail_field) and ($mail_field ne '') ) { > $host = $mail_field; > } I would use: my $host = $mail_field ? $mail_field : 'localhost' ; -- To unsubscribe, e-mail: beginners-unsubscr...@

Re: Problem with unless statement

2012-04-28 Thread sono-io
On Apr 28, 2012, Lesley Binks wrote: > To be robust, you might need to check that $xtra is defined AND has something > sensible in it using a regexp. Well, after being set straight to the error of my ways, I finally have code that seems to work in any situation: my $mail_field; # set

Re: Problem with unless statement

2012-04-28 Thread Lesley Binks
On Sat, Apr 28, 2012 at 08:00:09AM -0700, sono...@fannullone.us wrote: > Shawn, > > > are you sure this is what you want? > > I'm not sure of anything anymore. ;) > > I found something that sets $host properly: > > my $xtra = 'mail.example.com'; > my $host = 'localhost'; > That's a

Re: Problem with unless statement

2012-04-28 Thread John SJ Anderson
On Apr 28, 2012, at 10:40 AM, sono...@fannullone.us wrote: > On Apr 28, 2012, at 7:32 AM, Lesley Binks wrote: > >> Says the $host identifier will be assigned the value 'localhost' only if >> $extra >> is not defined. >> >> But $extra is defined as 'mail.example.com' so $host won't be. > >

Re: Problem with unless statement

2012-04-28 Thread Chris Charley
wrote in message news:65c0134b-14b8-4912-a22c-d92389b0b...@fannullone.us... Hi Shlomi, Thanks for getting back to me. What you should do is: [CODE] my $host; unless (defined($xtra)) { $host = 'localhost'; } Unfortunately, that gives me the same error. I had tried it before, but I was just

Re: Problem with unless statement

2012-04-28 Thread sono-io
Shawn, > are you sure this is what you want? I'm not sure of anything anymore. ;) I found something that sets $host properly: my $xtra = 'mail.example.com'; my $host = 'localhost'; $host = $xtra if (length $xtra > 0); Can anyone see any holes in this code? Marc --

Re: Problem with unless statement

2012-04-28 Thread Shawn H Corey
On 12-04-28 10:16 AM, sono...@fannullone.us wrote: I'm having a problem with the following code: #!/usr/bin/perl use strict; use warnings; my $xtra = 'mail.example.com'; my $host = 'localhost' unless (defined ($xtra)); # this is the same as saying: my $xtra = 'mail.example.com'; my

Re: Problem with unless statement

2012-04-28 Thread sono-io
Shlomi, > It's a bad idea to declare variables with a trailing conditional statement Never mind my "why" question. It finally dawned on me that the unless statement will not set the $host variable. And I thought sleeping on it would help. :\ Marc -- To unsubscribe, e-mail: beginners-

Re: Problem with unless statement

2012-04-28 Thread sono-io
On Apr 28, 2012, at 7:32 AM, Lesley Binks wrote: > Says the $host identifier will be assigned the value 'localhost' only if > $extra > is not defined. > > But $extra is defined as 'mail.example.com' so $host won't be. That makes sense. What I'm trying to do is set $host to one of the

Re: Problem with unless statement

2012-04-28 Thread sono-io
Hi Shlomi, Thanks for getting back to me. > What you should do is: > > [CODE] > > my $host; > unless (defined($xtra)) > { > $host = 'localhost'; > } Unfortunately, that gives me the same error. I had tried it before, but I was just trying for a one-liner. ;) > It's a b

Re: Problem with unless statement

2012-04-28 Thread Lesley Binks
On Sat, Apr 28, 2012 at 07:16:18AM -0700, sono...@fannullone.us wrote: > I'm having a problem with the following code: > > #!/usr/bin/perl > use strict; > use warnings; > > my $xtra = 'mail.example.com'; > > my $host = 'localhost' unless (defined ($xtra)); > > print $host; > > I ge

Re: Problem with unless statement

2012-04-28 Thread Lawrence Statton
On 04/28/2012 09:16 AM, sono...@fannullone.us wrote: I'm having a problem with the following code: #!/usr/bin/perl use strict; use warnings; my $xtra = 'mail.example.com'; my $host = 'localhost' unless (defined ($xtra)); print $host; I get the message "Use of uninitialized va

Re: Problem with unless statement

2012-04-28 Thread Shlomi Fish
Hi Marc, On Sat, 28 Apr 2012 07:16:18 -0700 sono...@fannullone.us wrote: > I'm having a problem with the following code: > > #!/usr/bin/perl > use strict; > use warnings; > > my $xtra = 'mail.example.com'; > > my $host = 'localhost' unless (defined ($xtra)); > It's a bad idea to declar

Problem with unless statement

2012-04-28 Thread sono-io
I'm having a problem with the following code: #!/usr/bin/perl use strict; use warnings; my $xtra = 'mail.example.com'; my $host = 'localhost' unless (defined ($xtra)); print $host; I get the message "Use of uninitialized value $host in print". Does anyone know why this doesn'