Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy do I get “uninitialized value” warnings when I use Date::Manip’s UnixDate in a sort block?
    text
    copied!<blockquote> <p>Related/possible duplicate: <a href="https://stackoverflow.com/questions/1263943/why-do-i-get-uninitialized-value-warnings-when-i-use-datemanips-sortbylength">Why do I get &quot;uninitialized value&quot; warnings when I use Date::Manip&#39;s sortByLength?</a></p> </blockquote> <p>This block of code:</p> <pre><code>my @sorted_models = sort { UnixDate($a-&gt;{'year'}, "%o") &lt;=&gt; UnixDate($b-&gt;{'year'}, "%o") } values %{$args{car_models}}; </code></pre> <p>kept generating the following <s>error</s> warning:</p> <pre> Use of uninitialized value in length at /.../Date/Manip.pm line 244. </pre> <p><a href="http://search.cpan.org/perldoc/Date::Manip" rel="nofollow noreferrer">Date::Manip</a> is a CPAN module. And line 244 of Date::Manip is found within the following block of code:</p> <pre><code># Get rid of a problem with old versions of perl no strict "vars"; # This sorts from longest to shortest element sub sortByLength { return (length $b &lt;=&gt; length $a); } use strict "vars"; </code></pre> <p>But then including this (printing out the actual Unix Date value to the console in the logger) before the block of code to sort the values: </p> <pre><code>foreach (values %{$args{car_models}}) { $g_logger-&gt;info(UnixDate($_-&gt;{'year'},"%o")); } </code></pre> <p>removed the <s>errors</s> warnings entirely. Why? And what is a good fix instead of doing all these logging statements?</p> <p>NOTE: None of the sorted values are undefined because when I printed them out in the logger, I could see that every one of them had a numerical value.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload