in reply to complaint: always testing defined()

no warnings "uninitialized"; # then it's just a regular check if ($params->{root} eq '') ...

Replies are listed 'Best First'.
Re^2: complaint: always testing defined()
by Joost (Canon) on Nov 03, 2007 at 11:14 UTC

      OP is checking for defined-ness solely to avoid generation of the warning (if the variable being checked against the empty string happens to be undefined). To me, that is whole reason for existence of this thread (from OP)...

      I find myself doing:
      if (defined($params->{root}) && $params->{root} eq '')
      to avoid a runtime warning.
        OP is checking for defined-ness solely to avoid generation of the warning
        Can I get the name of your crystal ball supplier?

        I would guess that the warning made the OP stop and think what branch to take in the undef case, and that the OP's code has a good chance of reflecting what was actually wanted.

        Has no warnings 'uninitialized'; been mentioned yet ?
        Update: Ooops .. yes, it has. (Sorry, missed it.)

        Cheers,
        Rob