Home: Perl Programming Help: Intermediate:
Useless use of defined operator in void context



artperl
Novice

Apr 26, 2015, 9:50 AM


Views: 3059
Useless use of defined operator in void context

Hello Gurus,

I have below warning (not error) which I can't seem to find anything explaining it from the internet. I have this from the line of code where I write something in the logger (using Log4Perl). In that info being written in the logger some variables (quite a number) included are undefined. I know it is not a good solution but my intention is to log list of variables so I can capture in the logs (in 1 line) which variables returned null/empty/undefined.

Any other way to capture this that I can get rid of the warning messages?


Zhris
Enthusiast

Apr 26, 2015, 10:13 AM


Views: 3056
Re: [artperl] Useless use of defined operator in void context

Show your code.

That warning indicates you are calling defined but are discarding the return value.

Not suggesting you should do this because you'll likely mask a bug, but you can turn off void context warnings using no warnings qw/void/;.


Laurent_R
Veteran / Moderator

Apr 26, 2015, 11:33 PM


Views: 3030
Re: [artperl] Useless use of defined operator in void context

It is a bit difficult to help without seeing the code that produced that warning and its context. Please show your code.


artperl
Novice

Apr 26, 2015, 11:40 PM


Views: 3024
Re: [Laurent_R] Useless use of defined operator in void context

Hi Chris, Laurent,

Apology for delayed reply... I decided to takeout the if condition that is causing the warning message. I just directly print the log regardless if some/or all of the variables are empty/undef:

$log->info("Data extracted >> Customer:", $CustName, "|Product:", $sProd, "|Lot:", $sLot, "|Stage:", $Tstage, "|Run Type:", $RetIndex, "|Alarm Type:", $repType, "|Parts Count:", $exeCount, "|Filename:", $FileN, "|Test Date:", $startT, "|SplitLotID:", $splitLot);

That took out the warning message & can still tell me for each file I process if there are some variables missing.

Thanks much for your continued support!!!... PerlGuru.com is helping me a lot in learning & doing some good stuff...


Laurent_R
Veteran / Moderator

Apr 27, 2015, 11:01 AM


Views: 3009
Re: [artperl] Useless use of defined operator in void context

I would recommend removing any warning by correcting the code. If there is a warning, then probably something is wrong in the code or in the data it employs.