为什么我得到“未初始化的值"?当我使用 Date::Manip 的 sortByLength 时出现警告? [英] Why do I get "uninitialized value" warnings when I use Date::Manip's sortByLength?

查看:28
本文介绍了为什么我得到“未初始化的值"?当我使用 Date::Manip 的 sortByLength 时出现警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Date::Manip 模块:

How might this block of code in Date/Manip.pm from the Date::Manip module:

#*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 <=> length $a);
}

use strict "vars";

我收到此警告:

Use of uninitialized value in length at /perl/lib/perl5.8/Date/Manip.pm line 244.

推荐答案

问题实际上不在那里;该函数只是使用无效(undef)参数调用.为了更好地追踪它的来源,试试这个:

The problem is not actually located there; the function is just being called with invalid (undef) parameters. To get a better trace of where it came from, try this:

$SIG{__WARN__} = sub {
  require Carp;
  Carp::confess("Warning: $_[0]");
};

这将打印所有警告的堆栈跟踪.

This will print a stacktrace for all warnings.

这篇关于为什么我得到“未初始化的值"?当我使用 Date::Manip 的 sortByLength 时出现警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆