Perl Useless use of private variable in void context
perl
Solution
Consider what happens when `$ooolog` is false. You end up executing
$ooo; # Useless
I think you were going for
$ooo = $ooolog ? $log . "/" . &getLog($log) : $ooo;
But it's simpler to do
$ooo = $log . "/" . &getLog($log) if $ooolog;
In the added question, you no longer get the warning because
$ooo; # Useless
has been replaced with
$fl = $fl. "/.ooo"; # Not useless
That said,
$ooodata ? ($fl = $fl. "/.ooo_data") : ($fl = $fl. "/.ooo");
is much better written as
$fl .= $ooodata ? "/.ooo_data" : "/.ooo";
If you have an assignment inside of a conditional operator, you are doing something wrong (something suboptimal and/or hard to read).
Problem
I looked at How can I resolve this case of "Useless use of a variable in a void context"? and it says to use . to concatenate which is what I did but I still the warning. Useless use of private variable in void context at /mysz/bin/heer line 79. ``` 43 sub getLog { 44 opendir(my $dh, $_[0]) || die "can't opendir $_[0]: $!"; 45 my @ooolog = grep {(/^\.oooo_log/)} readdir($dh); 46 closedir $dh; 47 return $ooolog[-1]; 48 } ... 79 $ooolog ? ($ooo = $log. "/". &getLog($log)) : $ooo; <--------- ... ``` Not quite sure how to fix Useless use of private variable in void context Anyone know how to fix it? EDIT: ``` 78 $ooodata ? ($fl = $fl. "/.ooo_data") : ($fl = $fl. "/.ooo"); ``` if its an `? :` issue then why is it not raising the warning at 78?