Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Re: Re: help needed on encoding a text file

by dakkar (Hermit)
on Apr 03, 2003 at 11:17 UTC ( #247726=note: print w/replies, xml ) Need Help??


in reply to Re: Re: help needed on encoding a text file
in thread help needed on encoding a text file

pack("N(N/a*)",$index{$key},$key)! meaning that the $index{$key} is written as a Number, and the $key as a length-prefixed string.

The parenthesis are for grouping. Their meaning is half-hidden in the documentation...

Regarding the error: I don't get it. I tested the code.

The unpack is right as it is: it means "a series of pairs of Numbers and length-prefixed strings (in unpack you must not put the *, see the docs)

-- 
        dakkar - Mobilis in mobile

Replies are listed 'Best First'.
Re: Re: Re: Re: help needed on encoding a text file
by bfdi533 (Friar) on Apr 07, 2003 at 19:38 UTC
    Ok, so I finally understand the N/a notation but am having trouble with this code. Seems that the () notation is pretty new as it is not in my Programming Perl, 2nd Edition and my perl 5.6.1 does not support it. But, my perl 5.8.0 does support it and is documented in its perlfunc manpage.

    Here is the error that I get with the perl 5.6.1:
    Invalid type in unpack: '(' at C:\Data\test\dcode2.pl line 8, <> chunk 1.

    I am not too sure how to go about "converting" this code to work with perl 5.6.1.

    BTW, still cannot get the code to work on perl 5.8.0 without an error with the "/" as stated earlier.

    Ed

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2022-05-20 15:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (73 votes). Check out past polls.

    Notices?