Re: Start reading at a specific index?

2019-02-02 Thread ToddAndMargo via perl6-users

> On Sat, Feb 2, 2019 at 9:02 PM ToddAndMargo via perl6-users
>  wrote:
>>
>> On 2/2/19 3:16 AM, Shlomi Fish wrote:
>>> On Sat, 2 Feb 2019 01:08:39 -0800
>>> ToddAndMargo via perl6-users  wrote:
>>>
>>>> Hi All,
>>>>
>>>> Is there a way to modify this to start reading at
>>>> a specific index?  And include how many bytes (300)
>>>> to read as well?
>>>>
>>>> my $FileHandle = open( $FileName, :bin, :ro );
>>>> my Buf $BinaryFile = $FileHandle.read( 300 );
>>>>
>>>> Many thanks,
>>>> -T
>>>
>>> See https://docs.perl6.org/routine/seek .
>>>
>>>
>>
>>
>> Thank you!
>>
>>
>> I am not sure exactly what they mean by "$whence".
>>
>> method seek(IO::Handle:D: Int:D $offset, SeekType:D $whence --> True)
>>
>>   SeekFromBeginning: The beginning of the file.
>>
>> my Bool $GoodRead = seek($FileHandle, $offset, SeekFromBeginning );
>> my Bool $GoodRead = seek.$FileHandle( $offset, SeekFromBeginning );
>>
>> Or do I need to assign something to a variable called "$whence"?
>>
>> Many thanks,
>> -T
>>

On 2/2/19 8:05 PM, Brad Gilbert wrote:

`$whence` means “whence”
 adverb
1.
 from what place or source.

So it should be one of the values of the `SeekType` enum

 say SeekType.enums.keys
 # (SeekFromCurrent SeekFromBeginning SeekFromEnd)

- `SeekFromCurrent` means it is relative to where it is currently (go
forward/backward)

 $fh.read(1);
 $fh.seek( -1, SeekFromCurrent);
 $fh.read(1); # same as previous `.read`

 # pretend to have read 5 bytes
 $fh.seek( 5, SeekFromCurrent );

- `SeekFromBeginning` means absolute position.

 # restart at beginning, and then skip forward 5 bytes
 $fh.seek( 5, SeekFromBeginning );

- `SeekFromEnd` means absolute position, except starting at the end of the file

 $fh.seek( -1, SeekFromEnd );
 $fh.read(1); # read last byte



Hi Brad.  I understand now.  Thank you!  -T


Re: Start reading at a specific index?

2019-02-02 Thread Brad Gilbert
`$whence` means “whence”
adverb
   1.
from what place or source.

So it should be one of the values of the `SeekType` enum

say SeekType.enums.keys
# (SeekFromCurrent SeekFromBeginning SeekFromEnd)

- `SeekFromCurrent` means it is relative to where it is currently (go
forward/backward)

$fh.read(1);
$fh.seek( -1, SeekFromCurrent);
$fh.read(1); # same as previous `.read`

# pretend to have read 5 bytes
$fh.seek( 5, SeekFromCurrent );

- `SeekFromBeginning` means absolute position.

# restart at beginning, and then skip forward 5 bytes
$fh.seek( 5, SeekFromBeginning );

- `SeekFromEnd` means absolute position, except starting at the end of the file

$fh.seek( -1, SeekFromEnd );
$fh.read(1); # read last byte

On Sat, Feb 2, 2019 at 9:02 PM ToddAndMargo via perl6-users
 wrote:
>
> On 2/2/19 3:16 AM, Shlomi Fish wrote:
> > On Sat, 2 Feb 2019 01:08:39 -0800
> > ToddAndMargo via perl6-users  wrote:
> >
> >> Hi All,
> >>
> >> Is there a way to modify this to start reading at
> >> a specific index?  And include how many bytes (300)
> >> to read as well?
> >>
> >>my $FileHandle = open( $FileName, :bin, :ro );
> >>my Buf $BinaryFile = $FileHandle.read( 300 );
> >>
> >> Many thanks,
> >> -T
> >
> > See https://docs.perl6.org/routine/seek .
> >
> >
>
>
> Thank you!
>
>
> I am not sure exactly what they mean by "$whence".
>
> method seek(IO::Handle:D: Int:D $offset, SeekType:D $whence --> True)
>
>  SeekFromBeginning: The beginning of the file.
>
> my Bool $GoodRead = seek($FileHandle, $offset, SeekFromBeginning );
> my Bool $GoodRead = seek.$FileHandle( $offset, SeekFromBeginning );
>
> Or do I need to assign something to a variable called "$whence"?
>
> Many thanks,
> -T
>
>
>
> --
> ~~
> Computers are like air conditioners.
> They malfunction when you open windows
> ~~


Re: Start reading at a specific index?

2019-02-02 Thread ToddAndMargo via perl6-users

On 2/2/19 3:16 AM, Shlomi Fish wrote:

On Sat, 2 Feb 2019 01:08:39 -0800
ToddAndMargo via perl6-users  wrote:


Hi All,

Is there a way to modify this to start reading at
a specific index?  And include how many bytes (300)
to read as well?

   my $FileHandle = open( $FileName, :bin, :ro );
   my Buf $BinaryFile = $FileHandle.read( 300 );

Many thanks,
-T


See https://docs.perl6.org/routine/seek .





Thank you!


I am not sure exactly what they mean by "$whence".

method seek(IO::Handle:D: Int:D $offset, SeekType:D $whence --> True)

SeekFromBeginning: The beginning of the file.

my Bool $GoodRead = seek($FileHandle, $offset, SeekFromBeginning );
my Bool $GoodRead = seek.$FileHandle( $offset, SeekFromBeginning );

Or do I need to assign something to a variable called "$whence"?

Many thanks,
-T



--
~~
Computers are like air conditioners.
They malfunction when you open windows
~~


Re: Start reading at a specific index?

2019-02-02 Thread Shlomi Fish
On Sat, 2 Feb 2019 01:08:39 -0800
ToddAndMargo via perl6-users  wrote:

> Hi All,
> 
> Is there a way to modify this to start reading at
> a specific index?  And include how many bytes (300)
> to read as well?
> 
>   my $FileHandle = open( $FileName, :bin, :ro );
>   my Buf $BinaryFile = $FileHandle.read( 300 );
> 
> Many thanks,
> -T

See https://docs.perl6.org/routine/seek .


-- 
-
Shlomi Fish   http://www.shlomifish.org/
http://is.gd/i5eMQd - Emma Watson’s Interview for a Software Dev Job

Q2: Busy people are unproductive. We are very productive and so we’re never
busy.
— http://www.shlomifish.org/humour/Star-Trek/We-the-Living-Dead/

Please reply to list if it's a mailing list post - http://shlom.in/reply .


Start reading at a specific index?

2019-02-02 Thread ToddAndMargo via perl6-users

Hi All,

Is there a way to modify this to start reading at
a specific index?  And include how many bytes (300)
to read as well?

 my $FileHandle = open( $FileName, :bin, :ro );
 my Buf $BinaryFile = $FileHandle.read( 300 );

Many thanks,
-T