From 0a8c0d48d11162cfd3b15ee1002983d0cc27190a Mon Sep 17 00:00:00 2001 From: Matteo Pasotti Date: Sat, 13 Sep 2014 01:24:40 +0200 Subject: - added apcat and find subroutines --- lib/AdminPanel/Shared.pm | 76 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) (limited to 'lib/AdminPanel/Shared.pm') diff --git a/lib/AdminPanel/Shared.pm b/lib/AdminPanel/Shared.pm index 6eb6edb..3165bf0 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 -- cgit v1.2.1