diff options
Diffstat (limited to 'SBO-Lib/lib/SBO/Lib')
| -rw-r--r-- | SBO-Lib/lib/SBO/Lib/Util.pm | 19 | 
1 files changed, 19 insertions, 0 deletions
diff --git a/SBO-Lib/lib/SBO/Lib/Util.pm b/SBO-Lib/lib/SBO/Lib/Util.pm index 39bdf65..52b1a9d 100644 --- a/SBO-Lib/lib/SBO/Lib/Util.pm +++ b/SBO-Lib/lib/SBO/Lib/Util.pm @@ -48,6 +48,7 @@ our @EXPORT_OK = (      print_failures      script_error      show_version +    slurp      uniq      usage_error      version_cmp @@ -419,6 +420,24 @@ sub show_version {    say '<http://sam.zoy.org/wtfpl/COPYING>';  } +=head2 slurp + +  my $data = slurp($fn); + +C<slurp()> takes a filename in C<$fn>, opens it, and reads in the entire file, +the contents of which is then returned. On error, it returns C<undef>. + +=cut + +sub slurp { +  my $fn = shift; +  return undef unless -f $fn; +  my ($fh, $exit) = open_read($fn); +  return undef if $exit; +  local $/; +  return scalar readline($fh); +} +  =head2 uniq    my @uniq = uniq(@duplicates);  | 
