On Sun, Mar 18, 2001 at 04:04:13PM +0000, Alan Fry wrote:
> At 9:09 am -0500 17/03/01, Ronald J Kimball wrote:
> >I don't think Bart has misunderstood the problem at all.
> 
> With the greatest respect I think you have both misunderstood what I 
> was driving at.

I think we're all misunderstanding each other.  :/


> >Take the first four characters, which indicate the type.
> 
> That IS the problem. Those four merry little characters (which may be 
> 'TEXT' or 'styl' or any number of things) are buried contiguously in 
> a mush of all sorts of other unrelated stuff. The problem is how to 
> pick them out of the mush.

The four characters I was referring to are not buried in a mush.  They're
the *first* four characters, which are at the beginning of the string.  :)


> >Take the next however many bytes, which indicate the length of the 
> >section of that type. Take the contents of the section, using the 
> >indicated length.
> >
> >Repeat as necessary.
> 
> Absolutely. If you were to look at the small script in my original 
> posting, you would see that is exactly what does happen.

Your script does something different from what I was intending to describe.

Here's a quick script that demonstrates what I think is the appropriate
approach (untested):

#!perl

my %size = ( TEXT => 'L',
             styl => 'S',
           );

{
  local $/;
  $string = <>;
}

while (length $string) {

  s/^(.{4})// or die "string too short";
  $type = $1;

  $size = $size{$type} or die "unknown type '$type'";

  $len = unpack $size, $string;

  (undef, $content, $string) = unpack "$size A$len A*", $string;

  print "Got '$type', $len bytes:\n$content\n";

  push @{$content{$type}}, $content;

}

__END__


Ronald

Reply via email to