Bee wrote:
Hi, I am very newbie for using the function 'pack', and here I have some questions :

Have you read the documentation for pack?

perldoc -f pack

And unpack?

perldoc -f unpack

Have you read the pack and unpack tutorial?

perldoc perlpacktut


Q1. Can I expect that pack can do this for me ?
    - compress a text file in smaller size

You could implement a compression algorithm with pack/unpack, if you really wanted to.


    - besize template 'aAuU', anything else tempplate I can use to prepare fix length 
data ?
    - if yes, but how do I assuming the block size is? In case,  if I write a binary 
file and I wanna use seek.

You are going to have to explain that in more detail.

Q2. Does the below results of code can be explained ?

my @arr = ('aa', '999', '!!');
my @back = ();

my @p = qw/a A Z b B h H c C s S i I l L n N v V j J f d F p P u U w x X/;
for $x(@p) { eval "\nprint \"$x ->\"; [EMAIL PROTECTED] = unpack \"${x}3${x}3${x}3\", \(pack \"${x}3${x}3${x}3\", [EMAIL PROTECTED]); print \"\<\$_>\" for [EMAIL PROTECTED]; print \"\\n\"; " };

You *DO* *NOT* have to use eval() to do that! The format strings are interpolated just like any other string.


for my $x ( @p ) {
    print "$x ->";
    my @back = unpack "${x}3${x}3${x}3", pack "${x}3${x}3${x}3", @arr;
    print "<$_>" for @back;
    print "\n";
    }



John
--
use Perl;
program
fulfillment

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to