ateague has asked for the wisdom of the Perl Monks concerning the following question:
UPDATE: I got my example to work with the following code:
Thank you Loops and 7stud for your help.say unpack '(C.*/X/xa@1)3', "\003\003\003abcdef"; # prints 'aaa' say unpack '(C.*/X/xa@1)3', "\005\004\003abcdef"; # prints 'cba'
Good morning! I am trying to get a better understanding of Perl's pack/unpack function.
I have a pretty good grasp of the "standard" templates, but I simply cannot get my head around the "@" and "." templates.
Does anyone know of (or have) any tutorials/examples that delve more in depth with the "@" and "." templates? perldoc pack and perlpacktut have the briefest mention of "@" and (to my eyes) no mention of ".".
A more concrete example: After playing around with pack and the "/" modifier, I came up with the following:
1. I understand what C/xa is doing, but what does @ do in this case?say unpack '(C/xa@)3', "\003\003\003abcdef"; # prints 'bcd' say unpack '(C/xa@)3', "\005\004\003abcdef"; # prints 'ddd'
2. How would I make the template skip from the absolute start of the string, rather than from a relative position?
e.g.:
say unpack '(C/xa@)3', "\003\003\003abcdef"; # prints 'bcd' - would li +ke 'aaa' say unpack '(C/xa@)3', "\005\004\003abcdef"; # prints 'ddd' - would li +ke 'cba'
Thank you for your time.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Pack/unpack - understanding the '@' and '.' templactes
by Loops (Curate) on Mar 31, 2013 at 07:11 UTC | |
Re: Pack/unpack - understanding the '@' and '.' templactes
by 7stud (Deacon) on Mar 31, 2013 at 10:01 UTC | |
by Anonymous Monk on Mar 31, 2013 at 22:53 UTC | |
Re: Pack/unpack - understanding the '@' and '.' templactes
by ambrus (Abbot) on Mar 31, 2013 at 11:14 UTC | |
by ateague (Monk) on Mar 31, 2013 at 14:27 UTC | |
Re: Pack/unpack - understanding the '@' and '.' templactes
by ateague (Monk) on Mar 31, 2013 at 14:44 UTC | |
Re: Pack/unpack - understanding the '@' and '.' templates
by Anonymous Monk on Mar 31, 2013 at 03:45 UTC |