Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

template in unpack

by uva (Sexton)
on Feb 10, 2006 at 09:18 UTC ( [id://529308]=perlquestion: print w/replies, xml ) Need Help??

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://529308]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (3)
As of 2025-01-21 21:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which URL do you most often use to access this site?












    Results (61 votes). Check out past polls.