aboutsummaryrefslogtreecommitdiff
path: root/challenge-028
diff options
context:
space:
mode:
authorLubos Kolouch <lubos@kolouch.net>2019-10-01 21:18:28 +0200
committerLubos Kolouch <lubos@kolouch.net>2019-10-01 21:18:28 +0200
commit5c6789e1f955c451d35388b15f7c19ade549d271 (patch)
treeba9092a68b213efe353d05180d759707c4302ef8 /challenge-028
parentd2c1ece666ac11016f51e756bef3d7f0c9eae661 (diff)
downloadperlweeklychallenge-club-5c6789e1f955c451d35388b15f7c19ade549d271.tar.gz
perlweeklychallenge-club-5c6789e1f955c451d35388b15f7c19ade549d271.tar.bz2
perlweeklychallenge-club-5c6789e1f955c451d35388b15f7c19ade549d271.zip
First commit, file ch-1.pl
Diffstat (limited to 'challenge-028')
-rw-r--r--challenge-028/lubos-kolouch/perl5/ch-1.pl47
1 files changed, 47 insertions, 0 deletions
diff --git a/challenge-028/lubos-kolouch/perl5/ch-1.pl b/challenge-028/lubos-kolouch/perl5/ch-1.pl
new file mode 100644
index 0000000000..e1982c24a4
--- /dev/null
+++ b/challenge-028/lubos-kolouch/perl5/ch-1.pl
@@ -0,0 +1,47 @@
+#!/usr/bin/perl
+#===============================================================================
+#
+# FILE: ch-1.pl
+#
+# USAGE: ./ch-1.pl
+#
+# DESCRIPTION: https://perlweeklychallenge.org/blog/perl-weekly-challenge-028/
+#
+# 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.
+#
+# OPTIONS: ---
+# REQUIREMENTS: ---
+# BUGS: ---
+# NOTES: ---
+# AUTHOR: Lubos Kolouch
+# ORGANIZATION:
+# VERSION: 1.0
+# CREATED: 09/30/2019 01:20:02 PM
+# REVISION: ---
+#===============================================================================
+
+use strict;
+use warnings;
+use feature qw/say/;
+
+sub get_file_status {
+ my $file = shift;
+
+ return "The file does not exist." unless -e $file;
+
+ return "The file is not readable." unless -r $file;
+
+ return "The file is empty." if -z $file;
+
+ return "The file is not regular." unless -f $file;
+
+ return "The file content is ascii." if -T $file;
+
+ return "The file content is binary.";
+}
+
+my $file = shift || die 'Usage: ch-1.pl filename';
+
+say get_file_status($file);
+
+