[icinga-checkins] icinga.org: icinga-core/fholzer/core: Add a slurp helper

git at icinga.org git at icinga.org
Sat Apr 21 20:23:45 CEST 2012


Module: icinga-core
Branch: fholzer/core
Commit: 9755f277092fb4592d4950f07934d1ac06ed6c0a
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=9755f277092fb4592d4950f07934d1ac06ed6c0a

Author: Alexander Wirt <formorer at debian.org>
Date:   Sat Apr 21 09:22:10 2012 +0200

Add a slurp helper

slurp($file) slurps in a whole file and returns a string afterwards.
Beware: it fails if the file does not exists, so don't forget a -f before.

---

 tools/icinga_verification.pl |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/tools/icinga_verification.pl b/tools/icinga_verification.pl
index c4c8e10..e58806b 100644
--- a/tools/icinga_verification.pl
+++ b/tools/icinga_verification.pl
@@ -309,3 +309,15 @@ sub which ($) {
     map { -x "$_/$binary" && return "$_/$binary" } reverse(split(':', $PATH));
     return undef;
 }
+
+sub slurp($) {
+    my $file = shift;
+    if (-f $file) {
+        open (my $fh, '<', $file)
+          or die "Could not open $file: $!";
+        return do { local $/; <$fh> };
+    } else {
+        die "$file does not exist";
+    }
+}
+





More information about the icinga-checkins mailing list