Tags:
create new tag
view all tags

Question

It seems that one can't set a WebPreferences variable to zero ('0'). It always evaluates to the empty string "". There's a fix in the Answer section, below.

  • TWiki version: 01 Sep 2001 release
  • Web server: Apache 1.3.x
  • Server OS: Linux 2.2.14
  • Web browser: Opera, Netscape, Mozilla, Lynx (all Linux)
  • Client OS: Linux 2.2.14

-- TrippLilley - 15 Nov 2001

Answer

TWiki::Prefs::getPrefsFromTopic uses this Perl idiom when it's evaluating preference variable values:

   $value = $2 || "";

The problem is that the assignment will fall through to the empty string ("") whenever $2 is false, which, by Perl's definition of "false", means whenever $2 is undefined, the empty string, or zero (0).

The fix is to check whether or not $2 is defined, since that's the only case for which we really want to force the empty string:

   $value = defined $2 ? $2 : "";

-- TrippLilley - 15 Nov 2001

Thanks for reporting. Copied it over to the Codev web as bug Codev.VariablesCantBeSetToZero

-- PeterThoeny - 16 Nov 2001

Edit | Attach | Watch | Print version | History: r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r2 - 2001-11-16 - PeterThoeny
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.