From: Justin C on
On 2010-02-18, sreservoir <sreservoir(a)gmail.com> wrote:
> On 2/18/2010 11:15 AM, Justin C wrote:
>> As some of you are probably aware I often have difficulty with Perl and
>> I ask for help here usually about once a month. I try to help myself
>> where I can, and sometimes, when I'm preparing a minimal example for
>> posting here, I find the solution to my problem. That's just happened
>> again, but only due to an error message I received from my text editor
>> and not Perl directly.
>>
>> I'm a Mac user, and code using TextMate<URL:http://macromates.com/>, it
>> has the ability to run code, I don't know how it does it, though, and
>> it's error message gave me the clue to the solution of my problem. The
>> error message on my Debian box was non-helpful.
>>
>> What is likely to be the cause of the non-helpful error message? Is the
>> version of Perl on my Mac likely more recent - I've just checked and on
>> my Debian box it's 5.10.0, while on the Mac it's 5.8.8. Does TextMate
>> have a built in Perl interpreter that gives better error messages?
>>
>> The error I saw on Debian:
>> Not a HASH reference at ... line...
>>
>> The error I saw from TextMate:
>> Can't coerce array into hash at ... line...
>
> the two messages are equally helpful if you think about it. The second
> doesn't even explicitly tell you it's a reference problem. If you need
> to, you can use diagnostics; alternatively, grep perldiag.

Maybe it's the way my brain (doesn't)work that made be deduce the
problem from that - I suppose the fact that I got two different errors
made me look more closely.

I've not used diagnostics before, and had forgotten of it's existence,
but I'll try and remember to use it in future.

> As for the line references, you can twiddle with your code so that all
> of the references aren't on a single line.

That's an idea. Thank you for your reply.

Justin.

--
Justin C, by the sea.
From: Justin C on
On 2010-02-18, Ben Morrow <ben(a)morrow.me.uk> wrote:
>
> Quoth Justin C <justin.0911(a)purestblue.com>:
>> As some of you are probably aware I often have difficulty with Perl and
>> I ask for help here usually about once a month. I try to help myself
>> where I can, and sometimes, when I'm preparing a minimal example for
>> posting here, I find the solution to my problem. That's just happened
>> again, but only due to an error message I received from my text editor
>> and not Perl directly.
>>
>> I'm a Mac user, and code using TextMate <URL:http://macromates.com/>, it
>> has the ability to run code, I don't know how it does it, though, and
>> it's error message gave me the clue to the solution of my problem. The
>> error message on my Debian box was non-helpful.
>>
>> What is likely to be the cause of the non-helpful error message? Is the
>> version of Perl on my Mac likely more recent - I've just checked and on
>> my Debian box it's 5.10.0, while on the Mac it's 5.8.8. Does TextMate
>> have a built in Perl interpreter that gives better error messages?
>
> You could have answered this easily by running the code from the
> command-line on your Mac. (You would have got the same error message as
> from TextMate.)
>
>> The error I saw on Debian:
>> Not a HASH reference at ... line...
>>
>> The error I saw from TextMate:
>> Can't coerce array into hash at ... line...
>
> The change in error message is due to the different perl versions. The
> 'Can't coerce...' message comes from the pseudohash code, which was
> removed in 5.10, whereas the 'Not a %s reference' is a generic message
> for situations where a value holds the wrong kind of ref.
>
> Before you start thinking this change was a bad idea, try running
>
> perl -le'my $x = [{a => 1}, "b"]; print $x->{a}'
>
> on both machines and consider how hard *that* would have been to debug
> with the 5.8 behaviour :).

That looks a bit circular, I suppose that that is your point. Under
5.8.8 I get 'b' and under 5.10.0 I get 'Not a HASH reference...', how
$x->{a} gets to be 'b' is the circular part. If you were expecting '1'
then, yes I can see how debugging that would be tough - especially as
"it worked", quite a shortage of warnings!

I have added "use diagnostics" to my "tesp.pl" file, where I put problem
code reduced to it's minimum parts so that I can work through the
problem. I'm in that file often enough that I'll see it and add it to
anything I'm working on that's giving me grief.

Thanks for the reply.

Justin.

--
Justin C, by the sea.
From: sreservoir on
On 2/19/2010 8:10 AM, Justin C wrote:
> On 2010-02-18, Ben Morrow<ben(a)morrow.me.uk> wrote:
>>
>> Quoth Justin C<justin.0911(a)purestblue.com>:
>>> As some of you are probably aware I often have difficulty with Perl and
>>> I ask for help here usually about once a month. I try to help myself
>>> where I can, and sometimes, when I'm preparing a minimal example for
>>> posting here, I find the solution to my problem. That's just happened
>>> again, but only due to an error message I received from my text editor
>>> and not Perl directly.
>>>
>>> I'm a Mac user, and code using TextMate<URL:http://macromates.com/>, it
>>> has the ability to run code, I don't know how it does it, though, and
>>> it's error message gave me the clue to the solution of my problem. The
>>> error message on my Debian box was non-helpful.
>>>
>>> What is likely to be the cause of the non-helpful error message? Is the
>>> version of Perl on my Mac likely more recent - I've just checked and on
>>> my Debian box it's 5.10.0, while on the Mac it's 5.8.8. Does TextMate
>>> have a built in Perl interpreter that gives better error messages?
>>
>> You could have answered this easily by running the code from the
>> command-line on your Mac. (You would have got the same error message as
>> from TextMate.)
>>
>>> The error I saw on Debian:
>>> Not a HASH reference at ... line...
>>>
>>> The error I saw from TextMate:
>>> Can't coerce array into hash at ... line...
>>
>> The change in error message is due to the different perl versions. The
>> 'Can't coerce...' message comes from the pseudohash code, which was
>> removed in 5.10, whereas the 'Not a %s reference' is a generic message
>> for situations where a value holds the wrong kind of ref.
>>
>> Before you start thinking this change was a bad idea, try running
>>
>> perl -le'my $x = [{a => 1}, "b"]; print $x->{a}'
>>
>> on both machines and consider how hard *that* would have been to debug
>> with the 5.8 behaviour :).
>
> That looks a bit circular, I suppose that that is your point. Under
> 5.8.8 I get 'b' and under 5.10.0 I get 'Not a HASH reference...', how
> $x->{a} gets to be 'b' is the circular part. If you were expecting '1'
> then, yes I can see how debugging that would be tough - especially as
> "it worked", quite a shortage of warnings!

pseudohashes are a sort of magic where
$t = [ { key => index, ... }, ... ];
causes
$t->{key}
to be the same as
$t->[index]

now forget I ever told you that, because it's obsolete and nobody ever
actually used it.

> I have added "use diagnostics" to my "tesp.pl" file, where I put problem
> code reduced to it's minimum parts so that I can work through the
> problem. I'm in that file often enough that I'll see it and add it to
> anything I'm working on that's giving me grief.

as long as you remember that diagnostics is meant for testing and such,
not production code.

--

"Six by nine. Forty two."
"That's it. That's all there is."
"I always thought something was fundamentally wrong with the universe"