`$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
<perl6-us...@perl.org> wrote:
>
> On 2/2/19 3:16 AM, Shlomi Fish wrote:
> > On Sat, 2 Feb 2019 01:08:39 -0800
> > ToddAndMargo via perl6-users <perl6-us...@perl.org> wrote:
> >
> >> Hi All,
> >>
> >> Is there a way to modify this to start reading at
> >> a specific index?  And include how many bytes (3000000)
> >> to read as well?
> >>
> >>        my $FileHandle     = open( $FileName, :bin, :ro );
> >>        my Buf $BinaryFile = $FileHandle.read( 3000000 );
> >>
> >> 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
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Reply via email to