thpfft has asked for the wisdom of the Perl Monks concerning the following question:

Is there any way for me to distinguish these two values?

$foo->{bar} = {}; $foo->{ball} = {()};

I haven't found anything yet, but i'm hoping the first will somehow be undefined where the second is merely empty. Any chance?

(i'm looking for a simple way to allow module callers to say 'these rules', 'all rules' or 'no rules'. Thought this might be the key.)

Replies are listed 'Best First'.
Re: {} vs {()}
by runrig (Abbot) on Sep 17, 2001 at 20:53 UTC
    You are creating two hash references which refer to empty hash arrays. There is no such thing as an undefined hash reference. Maybe you could do one or more of:
    { this_rule=>'some value' } # These rules {} # no rules 0 or undef # no rules (! UNIVERSAL::isa($var, 'HASH') and false) { all_rules=>1 } #all rules 1 # all rules ( ! UNIVERSAL::isa($var, 'HASH') and true)
Re: {} vs {()}
by perrin (Chancellor) on Sep 17, 2001 at 20:52 UTC
    No, since both of these are empty hash refs. You can certainly distinguish between $foo->{bar} = undef and $foo->{bar} = {} though.
(crazyinsomniac) Re: {} vs {()}
by crazyinsomniac (Prior) on Sep 18, 2001 at 10:34 UTC
    Is there a difference between () and (())?

    Is there a difference between ((),()) and (())?

    What about {(),()} and {} and {()}?

    I don't think there is any difference (i'm pretty confident).

    You should look at perlfunc, expecially exists and defined.

    ## What about $foo->{bar}; # no rules # exists $foo->{bar}={}; # all rules # exists and defined $foo->{bar}={ my => "# my rules" }; # exists and defined and has keys

     
    ___crazyinsomniac_______________________________________
    Disclaimer: Don't blame. It came from inside the void

    perl -e "$q=$_;map({chr unpack qq;H*;,$_}split(q;;,q*H*));print;$q/$q;"