in reply to Uninitialized value in string warnings (was: Warnings:)
Changing $a and $b to $u and $v. See perlvar for why.
The quotes are unnecessary, concatenation is enough.$u ||= ''; $v ||= ''; my $c = $u . $v;
You can look up perl's trouble messages in perldiag, which you will have (in the most relevant edition) on your local perl box.
Update: A word of explanation and a caveat. The '||=' operator tests for truth and assigns if false. That makes mine fail if $u or $v is zero. vagnerr's ternary on defined() does not suffer from this flaw.
Update 2 AM: $a and $b are package global variables internally defined in perl. They act as temporaries within sort to hold the two values currently being compared. It is dangerous to tread on those. Good news for you, $foo ||= 'bar' is an expression which returns $foo's final value, so the code above could be written as:
or even:my $c = ($u ||= '') . ($v ||= '');
The second does not modify $u and $v, and is well behaved for zero terms.my $c = (defined $u ? $u : '') . (defined $v ? $v : '');
Concerning program design: it's a good idea to have a definite place where a variable is always given a defined value. That places the burden on one statement, and lets other sections of code forget about these problems. Just another form of loose coupling.
After Compline,
Zaxo
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Warnings:
by Anonymous Monk on Jun 08, 2002 at 08:45 UTC | |
Re: Re: Warnings:
by Anonymous Monk on Jun 08, 2002 at 12:14 UTC |