in reply to Re^2: Help me update stubborn perlfaq answers!
in thread Help me update stubborn perlfaq answers!

The main work of the pack1D routine is in the for loop near the bottom. It takes an array of numbers and puts them into a string using a fixed size.
-------------
|int|int|int|
-------------
You can then unpack it with because you know the size of each element in the string.
#pack work = sv_2mortal(newSVpv("", 0)); for (i=0; i<=n; i++) { work2 = av_fetch( array, i, 0 ); /* Fetch */ if (work2==NULL) nval = 0.0; /* Undefined * else { if (SvROK(*work2)) goto errexit; /* Croak if reference [i.e. not 1D] */ nval = SvNV(*work2); } iscalar = (int) nval; sv_catpvn( work, (char *) &iscalar, sizeof(int)); } #unpack for (i=0; i<m; i++) { av_store( array, i, newSViv( (IV)ivar[i] ) ); }
-- gam3
A picture is worth a thousand words, but takes 200K.