uva has asked for the wisdom of the Perl Monks concerning the following question:

hello monks,, can you tell what the use of using x2 template in unpack. i read in the documentation as, x A null byte. X Back up a byte. but i didnt understand crealy. i also tried with the example. can you please give me some code which explain that.

Replies are listed 'Best First'.
Re: template in unpack
by GrandFather (Saint) on Feb 10, 2006 at 09:33 UTC
    use warnings; use strict; my $str = '1234567890'; my @unpacked = unpack 'A1 x2 A1 X2 A1', $str; print "@unpacked";

    Prints:

    1 4 3

    A1 gets the first character (1), x2 skips two (23), A1 gets one character (4), X2 backs up two characters (43), A1 gets one character (3).

    BTW print "@unpacked"; prints the elements in @unpacked with spaces between them as print join ' ', @unpacked; would.


    DWIM is Perl's answer to Gödel