It is just a Perl thing. Perl promotes undef to a 0 in printf since he treats it as a number ala "%1.10e " and the truth test ( ! $val ) treats 0, 0.0, "" and undef all as false. Thus it prints "0.00000" and then says "(undef)" because perl is trying to do-the-right-thing for you.
Returning undef as you do now is correct, we should just get a few more perl examples out there that deal with the difference between "define"d and false when it comes to the values returned by fetch. --mark -----Original Message----- From: Tobias Oetiker [mailto:[EMAIL PROTECTED] Sent: Thursday, March 15, 2001 1:21 PM To: steve rader Cc: [EMAIL PROTECTED] Subject: [rrd-developers] Re: RRDs::fetch zero values returns NaN Today steve rader wrote: | | > From: me | > The problem is that NaN values fetched with RRDs::fetch are now | > returned as 'undef' instead of the string 'NaN'. | | Now I find that RRDs::fetch is broke with respect to zero values: | with 1.0.33, RRDs::fetch of zero values returns 'undef'. | | I wrote a little script to demonstrate the problem... and here's | the results... | | chive(rader): rrdtool fetch -s -10min -e now \ | /usr/local/nrg/web/apache/Chive/Chive-tp.rrd AVERAGE \ | | tail -4 | 984673800: 1.1650888889e+00 | 984674100: 0.0000000000e+00 | 984674400: 0.0000000000e+00 | 984674700: NaN | | chive(rader): ./rrdfetch.pl \ | /usr/local/nrg/web/apache/Chive/Chive-tp.rrd AVERAGE \ | | tail -4 | 984673800: 1.1650888889e+00 | 984674100: 0.0000000000e+00 (undef) | 984674400: 0.0000000000e+00 (undef) | 984674700: 0.0000000000e+00 (undef) hmm not sure what is happening here, but the line in the perl bindings looks quite simple to me: av_push(line,(isnan(*datai) ? &PL_sv_undef : newSVnv(*datai))); anyone ? tobi | # | | use lib '/usr/local/rrdtool-1.0.33/lib/perl'; | use RRDs; | ($start,$step,$names,$data) = RRDs::fetch ("$ARGV[0]",'AVERAGE'); | if ( $error = RRDs::error ) { | print "rrdtool fetch failed: \"$error\"\n"; | exit 1; | } | $d_start = $start; | foreach $line (@$data) { | print " $d_start: "; | $d_start += $step; | foreach $val (@$line) { | printf "%1.10e ", $val; | if ( ! $val ) { print " (undef)"; } | } | print "\n"; | } | | | -- | Unsubscribe mailto:[EMAIL PROTECTED] | Help mailto:[EMAIL PROTECTED] | Archive http://www.ee.ethz.ch/~slist/rrd-developers | WebAdmin http://www.ee.ethz.ch/~slist/lsg2.cgi | | -- ______ __ _ /_ __/_ / / (_) Oetiker, Timelord & SysMgr @ EE-Dept ETH-Zurich / // _ \/ _ \/ / TEL: +41(0)1-6325286 FAX:...1517 ICQ: 10419518 /_/ \.__/_.__/_/ [EMAIL PROTECTED] http://ee-staff.ethz.ch/~oetiker -- Unsubscribe mailto:[EMAIL PROTECTED] Help mailto:[EMAIL PROTECTED] Archive http://www.ee.ethz.ch/~slist/rrd-developers WebAdmin http://www.ee.ethz.ch/~slist/lsg2.cgi -- Unsubscribe mailto:[EMAIL PROTECTED] Help mailto:[EMAIL PROTECTED] Archive http://www.ee.ethz.ch/~slist/rrd-developers WebAdmin http://www.ee.ethz.ch/~slist/lsg2.cgi
