[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] Simplification #2



>>>>> "BT" == Bennett Todd <bet@newritz.mordor.net> writes:

BT> 1999-06-30-20:47:00 Vicki Brown:
>> # Problem - pad out a string
>> [ with NULL bytes, to a length that's a multiple of 4 bytes ]

BT> I'd probably start with something like:

BT> 	$str .= "\0" x (4 - (length($str) % 4)) if length(str) % 4;

BT> then add or subtract one until I got the desired behavior:-).

How about,

	$str |= "\0" x (4 * int( (length($str) + 4) / 4));

Depending on the problem, you may not even need to pad the string itself.
E.g. Pack can add it in at the last instant ('@') or the appropriate number
of bytes can be written directly to the output.

I wonder if your puzzles should include the original situation.

<chaim>
-- 
Chaim Frenkel					     Nonlinear Knowledge, Inc.
chaimf@pobox.com				               +1-718-236-0183

==== Want to unsubscribe from Fun With Perl?
==== Well, if you insist... Send mail with body "unsubscribe" to
==== fwp-request@technofile.org