Perl-Sensitive Sunglasses | |
PerlMonks |
Unpack/formatby Reverend Phil (Pilgrim) |
on Feb 13, 2002 at 15:58 UTC ( [id://145185]=perlquestion: print w/replies, xml ) | Need Help?? |
Reverend Phil has asked for the wisdom of the Perl Monks concerning the following question:
Greetings, fellow citizens of planet earth. While I do not work in a shipping department, I do spend a great deal of time packing and unpacking. I've got a project which deals with fixed-width data records in various sized based on the kind of record we're getting. On rare occasions (because we all know how rare it is that our customers provide us with erroneous data) I get something a bit ugly from the customer. This can cause me heartache, hassle, and various other forms of gump. The problem occurs if the records are shorter than I expect. Actually, it's more absurd than that. Let me simplify with an example: For those unfamiliar, format strings ($fmt), allow me to cut and paste a drop of data from my infinitely handy Perl CD Bookshelf A - An ASCII string, will be space padded x - A null byte Strangely, if the string being unpacked is too short, but I'm looking for an ASCII char beyond the bounds of the string, things work fine as frogs hair (even though there are other 'x' chunks in the format beyond). If I'm looking for a null byte (ie: skipping a character) at the dead position of the string, the code dies with an 'x outside of string'. I'm wondering if other people have come across this as an issue, and how they've handled it. My thoughts are to check the length of each string vs. the expected length of the format string, but with a great deal of strings coming through, that would be tedious. Besides, rather than hard-coding the fmt string lengths, I'd rather have something more flexible to changes, which would leave me checking the length of each string vs. the calculated expected length of the format string. Just sounds ugly. Either way, I'm looking to avoid this 'x outside of string' hubbub. Thoughts? Feelings? Rhyme? Reason? -=rev=-
Back to
Seekers of Perl Wisdom
|
|