CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



artperl
Novice

Apr 26, 2015, 9:50 AM

Post #1 of 5 (2614 views)
Useless use of defined operator in void context Can't Post

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

Post #2 of 5 (2611 views)
Re: [artperl] Useless use of defined operator in void context [In reply to] Can't Post

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

Post #3 of 5 (2585 views)
Re: [artperl] Useless use of defined operator in void context [In reply to] Can't Post

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

Post #4 of 5 (2579 views)
Re: [Laurent_R] Useless use of defined operator in void context [In reply to] Can't Post

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

Post #5 of 5 (2564 views)
Re: [artperl] Useless use of defined operator in void context [In reply to] Can't Post

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.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives