Re: How to get offset position from unpack()?




Quoth "jl_post@xxxxxxxxxxx" <jl_post@xxxxxxxxxxx>:
Quoth "jl_p...@xxxxxxxxxxx" <jl_p...@xxxxxxxxxxx>:

However, there's something I want to do with unpack() that I
haven't figured out how to do:  I'd like to unpack part of a
string, but keep track of where the unpacking ended, so I can
resume unpacking the string (at a later time) where I left off.


On Feb 15, 1:48 pm, Ben Morrow <b...@xxxxxxxxxxxx> replied:
    ~% perl -E'my $x = "aaa"; say for unpack "a2.", $x'
    aa
    2
    ~%


Wow, thanks! The '.' character was exactly what I was looking for!

(I notice it's new in Perl 5.10, so if I'm working for platforms
that have an older version of Perl I'll just have to just the old "a*"
trick.)

I tried searching for "."'s behavior in "perldoc -f unpack",
"perldoc -f pack", and even "perldoc perlpacktut", but I couldn't find
where it mentions that it returns the offset when used with unpack().
Is there a place that explains this with a little more depth?

If there is, I didn't find it either. I just tried 'unpack "."' and
'unpack "@"' since they looked like likely possibilities, and "."
worked.

Ben

.



Relevant Pages

  • Re: Optimization help - reading out of /proc on Solaris
    ... string slicing and unpacking. ... we have a symbol mapping to an unpack format string segment ... #repeat the above with a new array instead of FIELDS and a new method name ... # # Print process table information for only pid 1001 ...
    (comp.lang.ruby)
  • Unpack When? Part II
    ... user interface or is it better to do all the work in Pick on the server and ... response to adding a string at the end of a previous string (ie like x += ... So I wonder if this would make a difference as to when to unpack? ... maybe we *should* unpack client-side. ...
    (comp.databases.pick)
  • Re: unpack "B*", 15
    ... You seem to be misunderstanding what unpack and pack do, ... pack takes a list of perl values, and packs them into a 'string', which ... packing of structs from a perl program in a simiar way a C program would ...
    (comp.lang.perl.misc)
  • How to get offset position from unpack()?
    ... The unpack() function is very, very useful for me, as I regularly ... do a lot of unpacking of non-Perl-created data strings to see what ... the string where I left off. ... I could calculate this offset myself by examining what was ...
    (comp.lang.perl.misc)
  • Re: Reading Images
    ... I'm just trying to load it and put on a quad. ...   name = GL.GenTextures; ... require to unpack the String. ...
    (comp.lang.ruby)