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 declare variables with a trailing conditional statement modifier (such as "if COND();" or "unless COND();"). What you should do is: [CODE] my $host; unless (defined($xtra)) { $host = 'localhost'; } [/CODE] Regards, Shlomi Fish > print $host; > > I get the message "Use of uninitialized value $host in print". Does > anyone know why this doesn't work? > > Thanks, > Marc -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ My Favourite FOSS - http://www.shlomifish.org/open-source/favourite/ * Backward compatibility is your worst enemy. * Backward compatibility is your users’ best friend. Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/