diff options
author | Pascal Rigaux <pixel@mandriva.com> | 2004-02-10 12:33:47 +0000 |
---|---|---|
committer | Pascal Rigaux <pixel@mandriva.com> | 2004-02-10 12:33:47 +0000 |
commit | 899c3751e2ff18f6142a0f7340763e79696f4e20 (patch) | |
tree | d42f2bbd70d26ba3dd8b89a151a49e3119bf6b39 | |
parent | b5edce8b592e111ba85f68ba54b2836ea189a0c1 (diff) | |
download | drakx-899c3751e2ff18f6142a0f7340763e79696f4e20.tar drakx-899c3751e2ff18f6142a0f7340763e79696f4e20.tar.gz drakx-899c3751e2ff18f6142a0f7340763e79696f4e20.tar.bz2 drakx-899c3751e2ff18f6142a0f7340763e79696f4e20.tar.xz drakx-899c3751e2ff18f6142a0f7340763e79696f4e20.zip |
add unpack_with_refs()
-rw-r--r-- | perl-install/common.pm | 21 |
1 files changed, 21 insertions, 0 deletions
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; |