NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.
All the Perl that's Practical to Extract and Report
Stories, comments, journals, and other submissions on use Perl; are Copyright 1998-2006, their respective owners.
What of binary manipulation? (Score:1)
So if I want to find a “magic number” byte sequence in a binary file, how do I do that in Perl 6?
Re: (Score:1)
According to S32/IO [perlcabal.org], the return type of
slurp(which reads a whole file at once) isStr|Buf. ABufis returned when a parameter:binis passed toslurp. After that, you can treat theBufyou get as an array (becauseBuf does Positional, and do as advanced indexing operations as you need to find your byte sequence.I wish I could show this with real, working code, but
Bufisn't implemented just yet in Rakudo.Re: (Score:1)
What kind of pattern matching facilities does
Bufsupport?Re:What of binary manipulation? (Score:1)
The spec is a bit silent on that point, so I asked on #perl6 [perlgeek.de]. The conclusion seems to be "convert it to a string if you want to pattern match".
Then again, if smartmatching with list semantics is what you're after, that should work. Something like
$buf ~~ (*, 104, 101, 108, 108, 111, *)to find "hello" in an ASCII-encoded Buf.Reply to This
Parent