OK, a method is something you call on an object, using a the dot operator.
A subroutine is an independent object installed into your current lexical
scope.

If write was a sub, it would work exactly as you described:
   48:   my $Handle = open( $DateFile, :rw )
   53:   write( $Handle, $OldDateTime );
And if you wanted to, you could even refer to it by name...
  my $func = &write;
  $func( $Handle, $DateThing );

But it's not a sub, so it needs to be invoked on the object:
   53:   $Handle.write($OldDateTime );
- or -
   67:   $Handle.write: $DateTime;

So the last section is the statements that will work.  Methods belong to
objects, so they can't be invoked except by calling them on the object.

On Fri, Sep 22, 2017 at 11:43 PM, ToddAndMargo <toddandma...@zoho.com>
wrote:

> On Sat, Sep 23, 2017 at 8:19 AM, ToddAndMargo <toddandma...@zoho.com
>>> <mailto:toddandma...@zoho.com>> wrote:
>>>
>>>     On 09/22/2017 11:09 PM, ToddAndMargo wrote:
>>>
>>>         Hi All,
>>>
>>>         https://docs.perl6.org/routine/write
>>>         <https://docs.perl6.org/routine/write>
>>>
>>>                 (IO::Handle) method write
>>>                 Defined as:
>>>                 method write(IO::Handle:D: Blob:D $buf --> True)
>>>
>>>                 Writes $buf to the filehandle. This method can be called
>>>                 even when the handle is not in binary mode.
>>>
>>>
>>>
>>>         This:
>>>              48:   my $Handle = open( $DateFile, :rw )
>>>              53:   write( $Handle, $OldDateTime );
>>>              67:   write( $Handle, $DateTime );
>>>
>>>         gives me this:
>>>              Undeclared routine: write used at lines 53, 67
>>>
>>>         Huh?  Seems to me I am follow the directions.  What am
>>>         I doing wrong?
>>>
>>>
>>>         Many thanks,
>>>         -T
>>>
>>>
>>>
>>>     This worked:
>>>          $Handle.print( "$DateTime\n" );
>>>
>>>     But I still what to know what was wrong with the
>>>     way I interpreted the manual
>>>
>>>     -T
>>>
>>
> On 09/22/2017 11:25 PM, Fernando Santagata wrote:
>
>> Hi,
>>
>> "write" is a method; its signature is
>>
>> method write(IO::Handle:D: Blob:D $buf --> True)
>>
>> so it has to be called as a method, not a sub.
>>
>> Also note the way the first argument is declared, as a IO::Handle:D:,
>> without a comma separating it from the second argument. That's the type of
>> the object to which the method write is to be applied.
>>
>> --
>> Fernando Santagata
>>
>
> Thank you!
>
> I  a-l-m-o-s-t  understand it.
>
> How to I turn the above into something that writes to a file?
>

Reply via email to