summaryrefslogtreecommitdiffstats
path: root/perl-install/common.pm
diff options
context:
space:
mode:
Diffstat (limited to 'perl-install/common.pm')
-rw-r--r--perl-install/common.pm25
1 files changed, 23 insertions, 2 deletions
diff --git a/perl-install/common.pm b/perl-install/common.pm
index c6d96682c..2fee51d59 100644
--- a/perl-install/common.pm
+++ b/perl-install/common.pm
@@ -6,9 +6,9 @@ use vars qw(@ISA %EXPORT_TAGS @EXPORT_OK $printable_chars $sizeof_int $bitof_int
@ISA = qw(Exporter);
%EXPORT_TAGS = (
- common => [ qw(_ __ min max sum bool ikeys member divide is_empty_array_ref add2hash set_new set_add round_up round_down first second top uniq translate untranslate) ],
+ common => [ qw(_ __ min max sum product bool ikeys member divide is_empty_array_ref add2hash set_new set_add round_up round_down first second top uniq translate untranslate) ],
functional => [ qw(fold_left) ],
- file => [ qw(dirname basename touch all glob_ cat_ chop_ mode) ],
+ file => [ qw(dirname basename touch all glob_ cat_ chop_ mode getVarsFromSh) ],
system => [ qw(sync makedev unmakedev psizeof strcpy gettimeofday syscall_ crypt_) ],
constant => [ qw($printable_chars $sizeof_int $bitof_int $SECTORSIZE) ],
);
@@ -26,6 +26,7 @@ sub __ { $_[0] }
sub min { fold_left(sub { $a < $b ? $a : $b }, @_) }
sub max { fold_left(sub { $a > $b ? $a : $b }, @_) }
sub sum { fold_left(sub { $a + $b }, @_) }
+sub product { fold_left(sub { $a * $b }, @_) }
sub first { $_[0] }
sub second { $_[1] }
sub top { $_[$#_] }
@@ -124,3 +125,23 @@ sub untranslate($@) {
foreach (@_) { translate($_) eq $s and return $_ }
die "untranslate failed";
}
+
+sub getVarsFromSh($) {
+ my %l;
+ local *F;
+ open F, $_[0] or return;
+ foreach (<F>) {
+ my ($v, $val, $val2) =
+ /^\s* # leading space
+ (\w+) = # variable
+ (
+ "([^"]*)" # double-quoted text "
+ | '([^']*)' # single-quoted text '
+ | [^'"\s]+ # normal text '
+ )
+ \s*$ # end of line
+ /x or next;
+ $l{$v} = $val2 || $val;
+ }
+ %l;
+}