> On Jan 8, 2004, at 7:45 AM, Dan Muey wrote:
> [..]
> >
> > Except I need to do this to about ten variabels all in a row. Which
> > gives me 10 lines with Bob's way and 40 with my very first example.
> > Boo for that! :)
> >
> [..]
>
> Have you thought about a simplification process?
> One of the tricks I do is say
>
> my ($var1,$var2,$var3,$var4) = ('' , '' , '', '');
>
> This way I have declared them and initialized them,
> so that they will not bounce with that 'use of undefined
> var at line X" error.
>
> This way when you get down to
>
> my $guts = ($use_second_choice)? $var2:$var1;
>
> you don't need to worry about the additional bit of
> making sure that it is
>
> my $guts = ($use_second_choice)? $var2: $var1 || '';
>
Wouldn't the || '' apply to $guts and not the use of uninitialized $var1,$var2,etc...
Anyway?
> Just a thought to think...
The vars to be assigned ($var1, $var2,etc...) come from a
database query so they are handled already earlier. So how
they are declared are irrelevant to the issue. (Yes they must be
initialized for a warnings safe environment and they are, just
assume that they are so the issue is not clouded by where they come from.)
The other thing the tricky part is:
I only want to assign it $var2 if($use_second_choice && !$var1)
I think the way you're doing it will asign it $value2 if $use_second_choice
regardless of if $var1 has a value or not.
So :
No matter what if $var1 has a value then assign $guts that value.
If $var 1 is empty and $use_second_value then assign it $var2
Other wise it shoufl be empty.
Bill's method work perfectly, namely:
$var1,$var2 and $ues_2 are declared and set earlier via a
DB query. So don't worry about where they are coming from.
my $value = $var1 || ($use_2 && $var2) || '';
So $value gets set to $var1 no matter what if($var1).
If it's not then it goes to the next step and is asking :"Ok $var1 has no
value do you want to use $var2 ?" if Yes give it $var2 if not say "sorry
I can't help you" and on the the next || which says "ok you shall receive
from the variable gods '' nothing!"
OR in longer terms:
my $guts = ''; # so that at least it has something assigned even if it's nothgin. :)
if($var1) { $guts = $var1; }
elsif($use_var2_if_var1_is_empty) { $guts = $var2; }
See what I'm trying to get at?
Bob's example does this quite perfectly, thanks again Bob!\
Dmuey
>
> ciao
> drieux
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>