raghuprasad241 has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

While referring to some tutorial on perl, I came across terms indirect object and regular object.

Below is an example of an indirect object vs regular object. So is an indirect object just an unnamed reference which does not belong to a class or not blessed ?
Indirect object: print { $rec–>{HANDLE} } "a string\n"; Regular object: use IO::Handle; $rec–>{HANDLE}–>print("a string\n");
Thanks in advance!

Replies are listed 'Best First'.
Re: Indirect object vs regular object
by Anonymous Monk on Mar 03, 2016 at 15:59 UTC

    It's not a different type of object, it's just a different syntax that does the same thing - the Indirect Object Syntax. For reasons documented in that link, its use is generally discouraged, but it's still used in print (and sometimes system/exec). You also still see it often in expressions like the following, because new is a keyword in other languages.

    my $file1 = new File $path, $data; # is the same as my $file2 = File->new($path, $data);
Re: Indirect object vs regular object
by perlfan (Parson) on Mar 03, 2016 at 20:54 UTC
    No, the reference in your examples is still $rec. But use direct syntax as it has been mentioned below.