http://www.perlmonks.org?node_id=1026297

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:

say unpack '(C.*/X/xa@1)3', "\003\003\003abcdef"; # prints 'aaa' say unpack '(C.*/X/xa@1)3', "\005\004\003abcdef"; # prints 'cba'
Thank you Loops and 7stud for your help.



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:

say unpack '(C/xa@)3', "\003\003\003abcdef"; # prints 'bcd' say unpack '(C/xa@)3', "\005\004\003abcdef"; # prints 'ddd'
1. I understand what C/xa is doing, but what does @ do in this case?

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.