Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: Pack/unpack - understanding the '@' and '.' templates

by Anonymous Monk
on Mar 31, 2013 at 03:45 UTC ( #1026323=note: print w/replies, xml ) Need Help??

in reply to [SOLVED] Pack/unpack - understanding the '@' and '.' templactes

update: :) good night

1. I understand what C/xa is doing, but what does @ do in this case? but what does @ do in this case?

Looks like a typo to me :) gives the use-case for this one, like a lot of these, its weird :)

Here is what I think I kinda know, remove the @ and you get

'x' outside of string in unpack

So I think @ means start from 0 , where 0 is the beginning for the innermost group (), instead of outside the end of the string :)

So C/x says read one byte/octet, then SKIP(x) that amount of bytes, so it eats the first \003, skips next 3 bytes , which are \003\003a

And its a group, so repeats that three times, each time the C/ eating up one byte, so it inches forward

Yeah, I don't think you can do this in one step, I think it's a 2 step operation like shown in the alignment pit

2. How would I make the template skip from the absolute start of the string, rather than from a relative position? e.g.:

Wait a minute, doesn't this mean you understand 1.?

I think you can't do that, now the original makes even less sense to me

Ok, here's the 2step

use 5.12.0; my $raw = "\003\003\003abcdef"; my @offsets = unpack '(C)3', $raw; my $chucks = join ' ', map { '@' . $_ . 'a' } @offsets; say $chucks; say for unpack $chucks, $raw; use 5.12.0; my $raw = "\003\003\003abcdef"; my @offsets = unpack '(C)3', $raw; my $chucks = join ' ', map { '@' . $_ . 'a' } @offsets; say $chucks; say for unpack $chucks, $raw; __END__ @3a @3a @3a a a a

update: HAHAHAHAHAHAAH I DID IT  (C/x! a@)3 gets you aaa, not sure how that works, makes no sense to me, but its straight from gappy alignment pit portion

This is what I don't like about pack/unpack,

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1026323]
[Corion]: marto: That's cool! I think my (home) desktop spends 30 seconds in the BIOS...
[Corion]: marto: Heh - currently they seem promising, but I think I'll stay with nVidia+Intel for the time being, as I've been bitten too often by bad AMD drivers
Discipulus is (still?) not a big fan of notepad++
[marto]: Corion, I think in the past this was a big problem for them. GPU driver wise the improve all the time. I use the open source drivers on my machine (old R9 270, 2GB) and had no problems
[Discipulus]: is not the problem with new hardware?
[marto]: notepad++ ticks all the boxes for me, it's a fine line between just enough, and bloat, in editors for me :P
[marto]: Discipulus]: less so than the modern intel CPUs
[marto]: also, AMD are faster at fixing the CPU microcode it would seem

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2017-07-27 08:58 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (407 votes). Check out past polls.