Prev: FAQ 6.6 How do I substitute case insensitively on the LHS while preserving case on the RHS?
Next: "un-meta" the control characters
From: John on 1 Nov 2009 10:32 Hi The following can cause a warning if undefined my $value=$PAR{$name}; What the best solution? my $value=$PAR{$name }or $value=''; or my $value=''; if (defined $PAR{$name}) {$value=$PAR{$name}} or is there a cleaner solution? Regards John
From: sln on 1 Nov 2009 10:45 On Sun, 1 Nov 2009 15:32:17 -0000, "John" <john1949(a)yahoo.com> wrote: >Hi > >The following can cause a warning if undefined > >my $value=$PAR{$name}; ^^^^^ only if undefined -sln
From: Andrew DeFaria on 1 Nov 2009 11:04 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"> <style type="text/css"> body { font: Helvetica, Arial, sans-serif; } p { font: Helvetica, Arial, sans-serif; } ..standout { font-family: verdana, arial, sans-serif; font-size: 12px; color: #993333; line-height: 13px; font-weight: bold; margin-bottom: 10px; } ..code { border-top: 1px solid #ddd; border-left: 1px solid #ddd; border-right: 2px solid #000; border-bottom: 2px solid #000; padding: 10px; margin-top: 5px; margin-left: 5%; margin-right: 5%; background: #ffffea; color: black; -moz-border-radius: 10px; } ..codedark { border-top: 10px solid #03f; border-left: 1px solid #ddd; border-right: 2px solid grey; border-bottom: 2px solid grey; padding: 10px; margin-top: 5px; margin-left: 5%; margin-right: 5%; background: black; color: yellow; -moz-border-radius: 10px; } #code { color: black; font-size: 14px; font-family: courier; padding-left: 5px; } #line-number { color: #804000; font-family: Arial; font-size: 14px; padding-right: 5px; border-right: 1px dotted #804000; } blockquote[type=cite] { padding: 0em .5em .5em .5em !important; border-right: 2px solid blue !important; border-left: 2px solid blue !important; } blockquote[type=cite] blockquote[type=cite] { border-right: 2px solid maroon !important; border-left: 2px solid maroon !important; } blockquote[type=cite] blockquote[type=cite] blockquote[type=cite] { border-right: 2px solid teal !important; border-left: 2px solid teal !important; } blockquote[type=cite] blockquote[type=cite] blockquote[type=cite] blockquote[type=cite] { border-right: 2px solid purple !important; border-left: 2px solid purple !important; } blockquote[type=cite] blockquote[type=cite] blockquote[type=cite] blockquote[type=cite] blockquote[type=cite] { border-right: 2px solid green !important; border-left: 2px solid green !important; } </style> </head> <body> On 11/01/2009 08:32 AM, John wrote: <blockquote id="mid_hck9lq_frj_1_news_albasani_net" cite="mid:hck9lq$frj$1(a)news.albasani.net" type="cite">Hi<br> <br> The following can cause a warning if undefined<br> <br> my $value=$PAR{$name};<br> <br> What the best solution?<br> <br> my $value=$PAR{$name }or $value='';<br> or<br> my $value=''; if (defined $PAR{$name}) {$value=$PAR{$name}}<br> or<br> is there a cleaner solution?<br> </blockquote> my $value ||= $PAR{$name}<br> <div class="moz-signature">-- <br> <a href="http://defaria.com">Andrew DeFaria</a><br> <small><font color="#999999">If a book about failures does not sell, is it a success?</font></small> </div> </body> </html>
From: Dr.Ruud on 1 Nov 2009 11:17 John wrote: > The following can cause a warning if undefined > > my $value=$PAR{$name}; my $value = defined($name) ? $PAR{$name} : undef; This means that $value itself can still be undef. Or did you mean 'name' in stead of $name? -- Ruud
From: John W. Krahn on 1 Nov 2009 12:16
Andrew DeFaria wrote: > On 11/01/2009 08:32 AM, John wrote: >> >> The following can cause a warning if undefined >> >> my $value=$PAR{$name}; >> >> What the best solution? >> >> my $value=$PAR{$name }or $value=''; >> or >> my $value=''; if (defined $PAR{$name}) {$value=$PAR{$name}} >> or >> is there a cleaner solution? > > my $value ||= $PAR{$name} That is exactly the same as saying: my $value = $PAR{$name} Because my() creates a variable that starts out undefined and an undefined variable is false so the || test will always fail. John -- The programmer is fighting against the two most destructive forces in the universe: entropy and human stupidity. -- Damian Conway |