Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Indirect Object Syntax

by choroba (Cardinal)
on Nov 06, 2021 at 20:48 UTC ( [id://11138528]=note: print w/replies, xml ) Need Help??


in reply to Indirect Object Syntax

Short demonstration of the problem:

#!/usr/bin/perl use warnings; use strict; use feature qw{ say }; sub new {} { package MyObj; sub new { bless { name => $_[1] }, $_[0] } sub string { join ', ', values %{ $_[0] } } } say 'MyObj'->new('obj1')->string; say new MyObj('obj2')->string;
This works as expected.
obj1 obj2

Now try moving the package definition to the end of the code.

obj1 Undefined subroutine &main::MyObj called at ... line 9.

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11138528]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-04-26 09:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found