Any Perl victims care to explain this?

Peter Barker pbarker at
Thu Apr 4 22:54:31 EST 2002

On Thu, 4 Apr 2002, Matthew Hawkins wrote:

> Think *I'm* confused?  When I print the ref() of the two values I'm
> getting back (I have two hash references to two different tables), one
> is returning an ARRAY (today, yesterday it was returning ARRAYREF and

Excuse me? ARRAYREF? I think your memory may be failing you. It _is_
possible to get that result back from ref, but it would involve some
serious hackery. "ref" tells you what you are a reference to. If you are a
reference to a reference to an array, you will see "ref", _not_ ARRAYREF.

> That's right, a nothing.  ref() is blank.  It's not a SCALAR, REF,

Get the fscking perl book. If something is not a ref, what did you expect
it to return?

[portaluser at funnelweb cgi-bin]$ perl -w
use strict;

print ref "foo";
[portaluser at funnelweb cgi-bin]$ 

> ARRAY, HASH, CODE or GLOB as the Perl documentation states ref returns.

Which documentation? The Perl Book, page 204: "The ref operator returns a
true value if EXPR is a reference the null string otherwise".

> Yesterday, it was a SCALAR, and an ARRAYREF, depending on the number of
> black taxis circling the tower of london or whatever, at the exact time
> I launched the script.  Oh, the MySQL db is static - its not changes
> there affecting the script as nothing is being altered in any way.

If you are repeatedly running the script, changing nothing, the script
contains no explicitly random elements and getting different values back,
this is extremely odd behaviour, and nothing I have ever seen.

> I don't think I'm the confused one.  I think that last one is funny

You're showing distinct signs of it, I'm afraid.

> scalar, since print will print it correctly (and being a good boy I've
> got strict on so print bitches if I try giving it non-scalar things).

print prints anything. In fact, print takes a list, not a scalar.

> But ref() doesn't think so, the SCALAR check in the superbuttugly
> conditional block is never entered, and the script dies in my catch-all
> clause with "Perl sucks" :-)

The "conditional block" is only necessary because you don't know the shape
of the data being returned in the hash. Some of your confusion may be
coming about by Tie::DBI being smart about what it returns you; you may be
inadvertently giving it different contexts, and it is changing its return
value to match. ($foo) = $hash{"key"} is quite different to $foo =
$hash{$key}.... if it's a tied hash, at least.

> The only reason I did this in Perl in the first place was because DBI
> and associates, plus the integrated regexping, are hard to match in
> other languages - and they're what I need to do. :(

Apparently Python's regexp stuff is getting to be quite nice. And Java's,

> I don't actually need any help (I'm going to redo the whole script in
> something that can be trusted, which I should have done in the first
> place with 20/20 hindsight), just BED (bitching et demonstratum?) that
> $value = $table->{'key'};
> is yet another Perl construct that is consistently inconsistent.

Stop and think about what you're claiming. Do you really think Perl
returns random results when you do a simple hash lookup? Do you really
think that you will get a random return type from a hash (in fact, you'll
only ever get a single return type from a single-element hash
lookup - scalar)

You're claiming that Perl is at fault here? You have shown you haven't
read the documentation, have given inconsistent bug reports and have
obviously spent too long trying to extend a system you do not understand
and have subsequently got frustrated with it. If you want to learn a
language, I would suggest spending some time getting to know the basic

Peter Barker                          |   N    _--_|\ /---- Barham, Vic 
Programmer,Sysadmin,Geek              | W + E /     /\                
pbarker at         |   S   \_,--?_*<-- Canberra      
You need a bigger hammer.             |             v    [35S, 149E]   
qq%I've never heard of it or used it, apart from finding it in the Camel
 book and saying "Oh god".% -- Onceler

More information about the linux mailing list