aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2019-10-02 16:05:40 +0100
committerGitHub <noreply@github.com>2019-10-02 16:05:40 +0100
commitd3bb983dad66cab3d2dd5cac1c3dd127b7d2279c (patch)
treece9ee36152ea2070f5408b99685b7cbdd2427eab
parent2744e01aa452f1a87438d6dc47d32f1211347b45 (diff)
parenta8cc33d2408eecc6ca6870dee70f772670a75161 (diff)
downloadperlweeklychallenge-club-d3bb983dad66cab3d2dd5cac1c3dd127b7d2279c.tar.gz
perlweeklychallenge-club-d3bb983dad66cab3d2dd5cac1c3dd127b7d2279c.tar.bz2
perlweeklychallenge-club-d3bb983dad66cab3d2dd5cac1c3dd127b7d2279c.zip
Merge pull request #710 from jacoby/master
First Challenge
-rwxr-xr-xchallenge-028/dave-jacoby/perl5/ch-1.pl31
1 files changed, 31 insertions, 0 deletions
diff --git a/challenge-028/dave-jacoby/perl5/ch-1.pl b/challenge-028/dave-jacoby/perl5/ch-1.pl
new file mode 100755
index 0000000000..7ddb99d2c7
--- /dev/null
+++ b/challenge-028/dave-jacoby/perl5/ch-1.pl
@@ -0,0 +1,31 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use utf8;
+use feature qw{ postderef say signatures state switch };
+no warnings
+ qw{ experimental::postderef experimental::smartmatch experimental::signatures };
+
+# Write a script to check the file content without explicitly
+# reading the content. It should accept file name with path as
+# command line argument and print "The file content is binary."
+# or else "The file content is ascii." accordingly.
+
+use Cwd 'abs_path';
+
+for my $file (@ARGV) {
+ filetest($file);
+}
+
+sub filetest($file) {
+ my $path = abs_path($file);
+ return unless -e $path;
+ return unless -f $path;
+ say $file;
+ if ( -T $path ) { say "\tThe file content is ascii" }
+ elsif ( -B $path ) { say "\tThe file content is binary" }
+}
+
+# the interesting thing is that zero-length files are accepted as both.
+# to keep that from happening, I used elsif and assumed ascii first