aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatteo Pasotti <matteo.pasotti@gmail.com>2014-09-13 01:24:40 +0200
committerMatteo Pasotti <matteo.pasotti@gmail.com>2014-09-13 01:24:40 +0200
commit0a8c0d48d11162cfd3b15ee1002983d0cc27190a (patch)
treea182cb809d236c255f392b4be35fcdb6bb531c34
parent9218a93758857ca7be2732d0e7c72a5eeee68ade (diff)
downloadmanatools-0a8c0d48d11162cfd3b15ee1002983d0cc27190a.tar
manatools-0a8c0d48d11162cfd3b15ee1002983d0cc27190a.tar.gz
manatools-0a8c0d48d11162cfd3b15ee1002983d0cc27190a.tar.bz2
manatools-0a8c0d48d11162cfd3b15ee1002983d0cc27190a.tar.xz
manatools-0a8c0d48d11162cfd3b15ee1002983d0cc27190a.zip
- added apcat and find subroutines
-rw-r--r--lib/AdminPanel/Shared.pm76
1 files changed, 76 insertions, 0 deletions
diff --git a/lib/AdminPanel/Shared.pm b/lib/AdminPanel/Shared.pm
index 6eb6edb5..3165bf04 100644
--- a/lib/AdminPanel/Shared.pm
+++ b/lib/AdminPanel/Shared.pm
@@ -87,6 +87,8 @@ our @EXPORT = qw(
md5sum
pathList2hash
distName
+ apcat
+ find
);
@@ -99,6 +101,80 @@ Version 0.01
our $VERSION = '0.01';
+
+#=============================================================
+
+=head2 apcat
+
+=head3 PARAMETERS
+
+$filename the name of the file to read
+
+=head3 OUTPUT
+
+$content the content of the selected text file inside
+
+=head3 DESCRIPTION
+
+This function return the content of $filename or false/0
+if it fails
+
+=cut
+
+#=============================================================
+
+#sub apcat {
+# my $fn = shift();
+# my $fh = undef;
+# my @content = ();
+# open($fh, "<", $fn) || return 0;
+# while(<$fh>)
+# {
+# push(@content,$_);
+# }
+# return \@content;
+#}
+
+sub apcat {
+ my $fn = shift();
+ my $fh = undef;
+ my $content = undef;
+ open($fh, "<", $fn) || return 0;
+ while(<$fh>)
+ {
+ $content .= $_;
+ }
+ return $content;
+}
+
+
+#=============================================================
+
+=head2 find
+
+=head3 PARAMETERS
+
+$code the CODE to search for inside the LIST
+
+=head3 OUTPUT
+
+returns the first element where CODE returns true (or returns undef)
+
+=head3 EXAMPLE
+
+find { /foo/ } "fo", "fob", "foobar", "foobir"
+gives "foobar"
+
+=cut
+
+#============================================================
+
+sub find(&@) {
+ my $f = shift;
+ $f->($_) and return $_ foreach @_;
+ undef;
+}
+
#=============================================================
=head2 distName