Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^6: Is this DBM::Deep behavior, or something with tie/bless? (ref)

by ysth (Canon)
on Feb 12, 2008 at 16:09 UTC ( #667599=note: print w/replies, xml ) Need Help??


in reply to Re^5: Is this DBM::Deep behavior, or something with tie/bless? (ref)
in thread Is this DBM::Deep behavior, or something with tie/bless?

So just fix Data::Compare. The fixes would probably be quite simple. The best fix is to change such things to:
if( ! eval { @$requires; 1 } ) { # Can't be used as an array ref
It is fine to use ref as a Boolean test. Any other uses of ref I simply can't recommend.

Note that the above trick doesn't work for CODE references so you have to resort to one of the second-best methods. I'd use the following:

Wouldn't that give a useless use warning? I would suggest this instead, which also works for CODE.
if( ! eval { \@$requires } ) { # Can't be used as an array ref
Pre-perl 5.10, either has a problem with arrayrefs being able to be dereferenced as pseudo-hashes.

Replies are listed 'Best First'.
Re^7: Is this DBM::Deep behavior, or something with tie/bless? (ref)
by tye (Sage) on Feb 12, 2008 at 16:50 UTC

    Yes, I have an open bug against Data::Diver for issuing warnings about pseudo-hashes due to this.

    You are right about the other warnings as well. Unfortunately, your alternative has other problems:

    my $foo; if( eval { \@$foo } ) { print $foo, $/; } __END__ ARRAY(0x34d10)

    In the case of CODE ref testing, there is a different problem:

    my $foo= "not_a_code_reference"; print "oops!\n" if eval { \&$foo };

    Of course, in some situations, one could consider the latter a feature. But mostly I think it would be unwanted.

    It is very sad that Perl still doesn't provide decent tools for determine the data type(s) of a reference. It is no wonder nobody gets this right.

    - tye        

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://667599]
help
Chatterbox?
[tye]: Is it just me, or do most python things have terrible logging/errors?
[LanX]: but but but ... the errors are nicely formatted!
[tye]: 1) The python stack traces show you the names of variables, not the values of variables. Almost never informative.
[LanX]: do you have a py job now?
[tye]: Right now I have errors trying to fetch stuff from graphite. It says 'apps not ready, check startup logs'. I eventually find the startup logs and see 'no apps found'. Looking for fixes to this problem...
[LanX]: no idea ... ask py monks! ;-p
[tye]: it turns out that this can be caused by almost anything going wrong. If you want to know what caused the problem, you have to try to load each app by-hand to see what problems it is having, because none of those will be logged.
[tye]: No, I write more Perl than py at work. But I have to deal with plenty of py things.
[tye]: py monks would just be offended.

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2017-09-21 20:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (252 votes). Check out past polls.

    Notices?