diff options
| author | Dave Jacoby <jacoby.david@gmail.com> | 2019-10-02 10:46:49 -0400 |
|---|---|---|
| committer | Dave Jacoby <jacoby.david@gmail.com> | 2019-10-02 10:46:49 -0400 |
| commit | a8cc33d2408eecc6ca6870dee70f772670a75161 (patch) | |
| tree | 59b5aae8adc1e5372ce735cd6292390838fcd58c /challenge-028 | |
| parent | 44b0834328f2aacdbbb75e52a9b6f899f110edcb (diff) | |
| download | perlweeklychallenge-club-a8cc33d2408eecc6ca6870dee70f772670a75161.tar.gz perlweeklychallenge-club-a8cc33d2408eecc6ca6870dee70f772670a75161.tar.bz2 perlweeklychallenge-club-a8cc33d2408eecc6ca6870dee70f772670a75161.zip | |
First Challenge
Diffstat (limited to 'challenge-028')
| -rwxr-xr-x | challenge-028/dave-jacoby/perl5/ch-1.pl | 31 |
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 |
