Daniel Beardsmore has asked for the wisdom of the Perl Monks concerning the following question:
This is a bit of a hard one to explain succinctly!
Given an object built on a hash reference:
my $self = bless( { log => undef, }, $package );
Perl won't allow you to use this!
You can't write this:
say $self->{'log'} 'Message';This results in: String found where operator expected at ..., near "} ''" (Missing operator before ''?)
Having converted this module from package globals to OOP, I started getting bizarre crashes: "Not a CODE reference"
This, I tracked down to:
say $self->{'log'} ($detailedMessage // $message);Here, having an object property as a direct object file handle causes Perl to defecate building materials.
It doesn't seem to be a common thing to want to do, as I'm not seeing any suggestion that anyone else is seeing this fail.
It's not a huge deal to have to copy the file handle reference into a local variable to use it with say, but it's just very odd and it would be nice to understand what it's tripping up over here.
This is perl 5, version 20, subversion 2 (v5.20.2) built for x86_64-linux-gnu-thread-multi. The code begins:
use strict; use warnings; use utf8; use 5.10.0; no warnings 'experimental::smartmatch';
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Object property not legal as direct object?
by hippo (Archbishop) on Nov 09, 2016 at 11:25 UTC | |
by Daniel Beardsmore (Initiate) on Nov 09, 2016 at 11:46 UTC | |
by BillKSmith (Monsignor) on Nov 09, 2016 at 20:51 UTC | |
|
Re: Object property not legal as direct object?
by dave_the_m (Monsignor) on Nov 09, 2016 at 11:24 UTC | |
|
Re: Object property not legal as direct object?
by choroba (Cardinal) on Nov 09, 2016 at 14:42 UTC | |
|
Re: Object property not legal as direct object?
by zwon (Abbot) on Nov 09, 2016 at 22:03 UTC |