.\" Automatically generated by Pod::Man 4.10 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Parse::Binary::FixedFormat 3pm" .TH Parse::Binary::FixedFormat 3pm "2018-12-20" "perl v5.28.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Parse::Binary::FixedFormat \- Convert between fixed\-length fields and hashes .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Parse::Binary::FixedFormat; \& \& my $tarhdr = \& new Parse::Binary::FixedFormat [ qw(name:a100 mode:a8 uid:a8 gid:a8 size:a12 \& mtime:a12 chksum:a8 typeflag:a1 linkname:a100 \& magic:a6 version:a2 uname:a32 gname:a32 \& devmajor:a8 devminor:a8 prefix:a155) ]; \& my $buf; \& read TARFILE, $buf, 512; \& \& # create a hash from the buffer read from the file \& my $hdr = $tarhdr\->unformat($buf); # $hdr gets a hash ref \& \& # create a flat record from a hash reference \& my $buf = $tarhdr\->format($hdr); # $hdr is a hash ref \& \& # create a hash for a new record \& my $newrec = $tarhdr\->blank(); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" \&\fBParse::Binary::FixedFormat\fR can be used to convert between a buffer with fixed-length field definitions and a hash with named entries for each field. The perl \f(CW\*(C`pack\*(C'\fR and \f(CW\*(C`unpack\*(C'\fR functions are used to perform the conversions. \fBParse::Binary::FixedFormat\fR builds the format string by concatenating the field descriptions and converts between the lists used by \f(CW\*(C`pack\*(C'\fR and \f(CW\*(C`unpack\*(C'\fR and a hash that can be reference by field name. .SH "METHODS" .IX Header "METHODS" \&\fBParse::Binary::FixedFormat\fR provides the following methods. .SS "new" .IX Subsection "new" To create a converter, invoke the \fBnew\fR method with a reference to a list of field specifications. .PP .Vb 2 \& my $cvt = \& new Parse::Binary::FixedFormat [ \*(Aqfield\-name:descriptor:count\*(Aq, ... ]; .Ve .PP Field specifications contain the following information. .IP "field-name" 4 .IX Item "field-name" This is the name of the field and will be used as the hash index. .IP "descriptor" 4 .IX Item "descriptor" This describes the content and size of the field. All of the descriptors get strung together and passed to \fBpack\fR and \fBunpack\fR as part of the template argument. See \fBperldoc \-f pack\fR for information on what can be specified here. .Sp Don't use repeat counts in the descriptor except for string types (\*(L"a\*(R", \*(L"A\*(R", \*(L"h, \*(R"H\*(L", and \*(R"Z"). If you want to get an array out of the buffer, use the \f(CW\*(C`count\*(C'\fR argument. .IP "count" 4 .IX Item "count" This specifies a repeat count for the field. If specified as a non-zero value, this field's entry in the resultant hash will be an array reference instead of a scalar. .SS "unformat" .IX Subsection "unformat" To convert a buffer of data into a hash, pass the buffer to the \&\fBunformat\fR method. .PP .Vb 1 \& $hashref = $cvt\->unformat($buf); .Ve .PP Parse::Binary::FixedFormat applies the constructed format to the buffer with \&\f(CW\*(C`unpack\*(C'\fR and maps the returned list of elements to hash entries. Fields can now be accessed by name though the hash: .PP .Vb 2 \& print $hashref\->{field\-name}; \& print $hashref\->{array\-field}[3]; .Ve .SS "format" .IX Subsection "format" To convert the hash back into a fixed-format buffer, pass the hash reference to the \fBformat\fR method. .PP .Vb 1 \& $buf = $cvt\->format($hashref); .Ve .SS "blank" .IX Subsection "blank" To get a hash that can be used to create a new record, call the \&\fBblank\fR method. .PP .Vb 1 \& $newrec = $cvt\->blank(); .Ve .SH "ATTRIBUTES" .IX Header "ATTRIBUTES" Each Parse::Binary::FixedFormat instance contains the following attributes. .IP "Names" 4 .IX Item "Names" Names contains a list of the field names for this variant. .IP "Count" 4 .IX Item "Count" Count contains a list of occurrence counts. This is used to indicate which fields contain arrays. .IP "Format" 4 .IX Item "Format" Format contains the template string for the Perl \fBpack\fR and \fBunpack\fR functions. .SH "AUTHORS" .IX Header "AUTHORS" Audrey Tang .PP Based on Data::FixedFormat, written by Thomas Pfau http://nbpfaus.net/~pfau/. .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright 2004\-2009 by Audrey Tang . .PP Copyright (C) 2000,2002 Thomas Pfau. All rights reserved. .PP This module is free software; you can redistribute it and/or modify it under the terms of the \s-1GNU\s0 General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. .PP This library is distributed in the hope that it will be useful, but \&\s-1WITHOUT ANY WARRANTY\s0; without even the implied warranty of \&\s-1MERCHANTABILITY\s0 or \s-1FITNESS FOR A PARTICULAR PURPOSE.\s0 See the \s-1GNU\s0 Library General Public License for more details. .PP You should have received a copy of the \s-1GNU\s0 General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place \- Suite 330, Boston, \s-1MA 02111\-1307, USA.\s0