Start reading at a specific index?

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
0
perl6
2/2/2019 9:08:39 AM
perl.perl6.users 1168 articles. 0 followers. Follow

4 Replies
42 Views

Similar Articles

[PageSpeed] 24

On Sat, 2 Feb 2019 01:08:39 -0800
ToddAndMargo via perl6-users <perl6-users@perl.org> wrote:

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

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


--=20
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
http://is.gd/i5eMQd - Emma Watson=E2=80=99s Interview for a Software Dev Job

Q2: Busy people are unproductive. We are very productive and so we=E2=80=99=
re never
busy.
    =E2=80=94 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 .
0
shlomif
2/2/2019 11:16:55 AM
On 2/2/19 3:16 AM, Shlomi Fish wrote:
> On Sat, 2 Feb 2019 01:08:39 -0800
> ToddAndMargo via perl6-users <perl6-users@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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0
perl6
2/3/2019 3:02:04 AM
`$whence` means =E2=80=9Cwhence=E2=80=9D
    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-users@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-users@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     =3D open( $FileName, :bin, :ro );
> >>        my Buf $BinaryFile =3D $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 =3D seek($FileHandle, $offset, SeekFromBeginning );
> my Bool $GoodRead =3D 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
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0
b2gills
2/3/2019 4:05:25 AM
 > On Sat, Feb 2, 2019 at 9:02 PM ToddAndMargo via perl6-users
 > <perl6-users@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-users@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     =3D open( $FileName, :bin, :ro );
 >>>>         my Buf $BinaryFile =3D $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 =3D seek($FileHandle, $offset, SeekFromBeginning );=

 >> my Bool $GoodRead =3D 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 =E2=80=9Cwhence=E2=80=9D
>      adverb
>     1.
>          from what place or source.
>=20
> So it should be one of the values of the `SeekType` enum
>=20
>      say SeekType.enums.keys
>      # (SeekFromCurrent SeekFromBeginning SeekFromEnd)
>=20
> - `SeekFromCurrent` means it is relative to where it is currently (go
> forward/backward)
>=20
>      $fh.read(1);
>      $fh.seek( -1, SeekFromCurrent);
>      $fh.read(1); # same as previous `.read`
>=20
>      # pretend to have read 5 bytes
>      $fh.seek( 5, SeekFromCurrent );
>=20
> - `SeekFromBeginning` means absolute position.
>=20
>      # restart at beginning, and then skip forward 5 bytes
>      $fh.seek( 5, SeekFromBeginning );
>=20
> - `SeekFromEnd` means absolute position, except starting at the end of =
the file
>=20
>      $fh.seek( -1, SeekFromEnd );
>      $fh.read(1); # read last byte
>=20

Hi Brad.  I understand now.  Thank you!  -T
0
perl6
2/3/2019 6:38:27 AM
Reply: