summaryrefslogtreecommitdiffstats
path: root/perl-install/common.pm
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2004-02-10 12:33:47 +0000
committerPascal Rigaux <pixel@mandriva.com>2004-02-10 12:33:47 +0000
commit899c3751e2ff18f6142a0f7340763e79696f4e20 (patch)
treed42f2bbd70d26ba3dd8b89a151a49e3119bf6b39 /perl-install/common.pm
parentb5edce8b592e111ba85f68ba54b2836ea189a0c1 (diff)
downloaddrakx-899c3751e2ff18f6142a0f7340763e79696f4e20.tar
drakx-899c3751e2ff18f6142a0f7340763e79696f4e20.tar.gz
drakx-899c3751e2ff18f6142a0f7340763e79696f4e20.tar.bz2
drakx-899c3751e2ff18f6142a0f7340763e79696f4e20.tar.xz
drakx-899c3751e2ff18f6142a0f7340763e79696f4e20.zip
add unpack_with_refs()
Diffstat (limited to 'perl-install/common.pm')
-rw-r--r--perl-install/common.pm21
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;