From 899c3751e2ff18f6142a0f7340763e79696f4e20 Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Tue, 10 Feb 2004 12:33:47 +0000 Subject: add unpack_with_refs() --- perl-install/common.pm | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'perl-install') diff --git a/perl-install/common.pm b/perl-install/common.pm index e01d835db..6438fbc59 100644 --- a/perl-install/common.pm +++ b/perl-install/common.pm @@ -285,5 +285,26 @@ sub check_for_xserver() { return $::xtest; } +#- special unpack +#- - returning an array refs for each element like "s10" +#- - handling things like s10* at the end of the format +sub unpack_with_refs { + my ($format, $s) = @_; + my $initial_format = $format; + my @r; + while ($format =~ s/\s*(\w(\d*))(\*?)\s*//) { + my ($sub_format, $nb, $many) = ($1, $2, $3); + $many && $format and internal_error("bad * in the middle of format in $initial_format"); + + my $done = $many && !length($s); + while (!$done) { + my @l = unpack("$sub_format a*", $s); + $s = pop @l; + push @r, $nb ? \@l : @l; + $done = !$many || !length($s); + } + } + @r; +} 1; -- cgit v1.2.1