Re: How do I use chr inside a regex?

2019-02-02 Thread ToddAndMargo via perl6-users
On 2/1/19 11:32 PM, JJ Merelo wrote: Hi, El sáb., 2 feb. 2019 a las 7:48, ToddAndMargo via perl6-users (mailto:perl6-users@perl.org>>) escribió: Hi All, How do I use chr inside a regex.  In the below, how do I get rid of $y? $ p6 'my Str $x=chr(0x66)~chr(0x77); my Str

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

faster than index?

2019-02-02 Thread ToddAndMargo via perl6-users
Hi All, What is the fastest way to find the index of a sub string in a string? -T

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

Re: faster than index?

2019-02-02 Thread Brad Gilbert
`.index` is going to be the fastest because it is directly using NQP ops which are built into the VM. 'abcdefg'.index('de'); # 3 If you want all of the indexes, use `.indices` 'abcdefabc'.indices('abc'); # 0, 6 `.index` will return `Nil` if it doesn't find anything, and `.indices` will

Fastest way to convert from a Buf to a Str?

2019-02-02 Thread ToddAndMargo via perl6-users
Hi All, I need to read a file into a buffer (NO CONVERSIONS!) and then convert it to a string (again with no conversions). I have been doing this: for ( @$BinaryFile ) -> $Char { $StrFile ~= chr($Char); } But it takes a bit of time. What is the fastest way to do this? I guess there is

Re: binary test and position?

2019-02-02 Thread ToddAndMargo via perl6-users
> On Sat, Feb 2, 2019 at 10:05 PM ToddAndMargo via perl6-users > wrote: >> >> On 2/2/19 6:09 AM, Brad Gilbert wrote: >>> sub buf-index ( Buf $buf, +@match ) { >>> my $elems = @match.elems; >>> $buf.rotor( $elems => 1 - $elems ).first(* eqv @match.List, :k) >>> }

"index" source code?

2019-02-02 Thread ToddAndMargo via perl6-users
Hi All, Was the subroutine "index" written Perl6? If so, where can I view the source code? Many thanks, -T

Fastest way to convert from a Buf to a Str?

2019-02-02 Thread ToddAndMargo via perl6-users
Hi All, I need to read a file into a buffer (NO CONVERSIONS!) and then convert it to a string (again with no conversions). I have been doing this: for ( @$BinaryFile ) -> $Char { $StrFile ~= chr($Char); } But it takes a bit of time. What is the fastest way to do this? I guess there is

Re: Fastest way to convert from a Buf to a Str?

2019-02-02 Thread ToddAndMargo via perl6-users
> > On Sat, Feb 2, 2019 at 9:23 PM ToddAndMargo via perl6-users > wrote: >> >> Hi All, >> >> I need to read a file into a buffer (NO CONVERSIONS!) >> and then convert it to a string (again with no >> conversions). >> >> I have been doing this: >> >> for ( @$BinaryFile ) -> $Char { $StrFile

Re: binary test and position?

2019-02-02 Thread ToddAndMargo via perl6-users
On 2/2/19 6:09 AM, Brad Gilbert wrote: sub buf-index ( Buf $buf, +@match ) { my $elems = @match.elems; $buf.rotor( $elems => 1 - $elems ).first(* eqv @match.List, :k) } my $buf = Buf[uint8].new(0x4D, 0x5A, 0x90, 0x00, 0x03); say buf-index( $buf, (0x90,

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

Re: binary test and position?

2019-02-02 Thread Brad Gilbert
Subs do not need to have a `return` statement if it is returning the last value. You also broke the return value of the subroutine that I wrote by assigning it to a variable. What I wrote would return `Nil` if it failed to find a match, yours will return an undefined `Int`. It should return

Re: Fastest way to convert from a Buf to a Str?

2019-02-02 Thread Brad Gilbert
This: for ( @$BinaryFile ) -> $Char { $StrFile ~= chr($Char); } is better written as my $StrFile = $BinaryFile.map(*.chr).reduce(* ~ *); It is also exactly equivalent to just e # if $BinaryFile is a Buf my $StrFile = $BinaryFile.decode('latin1'); # if it isn't my

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?

Re: binary test and position?

2019-02-02 Thread Brad Gilbert
sub buf-index ( Buf $buf, +@match ) { my $elems = @match.elems; $buf.rotor( $elems => 1 - $elems ).first(* eqv @match.List, :k) } my $buf = Buf[uint8].new(0x4D, 0x5A, 0x90, 0x00, 0x03); say buf-index( $buf, (0x90, 0x00, 0x03)); # 2 On Fri, Feb 1, 2019 at 11:02 PM

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,

Re: binary test and position?

2019-02-02 Thread ToddAndMargo via perl6-users
> On Fri, Feb 1, 2019 at 11:02 PM ToddAndMargo via perl6-users> wrote: >> >> On 2/1/19 8:26 PM, ToddAndMargo via perl6-users wrote: >>> On 2/1/19 8:07 PM, ToddAndMargo via perl6-users wrote: On 2/1/19 8:03 PM, ToddAndMargo via perl6-users wrote: > > On Fri, Feb 1, 2019 at 9:37 PM

Re: faster than index?

2019-02-02 Thread ToddAndMargo via perl6-users
On 2/2/19 6:21 AM, Brad Gilbert wrote: `.index` is going to be the fastest because it is directly using NQP ops which are built into the VM. 'abcdefg'.index('de'); # 3 If you want all of the indexes, use `.indices` 'abcdefabc'.indices('abc'); # 0, 6 `.index` will return `Nil` if it