From 87fb34a6e91686a017033aae0276891e846fb14d Mon Sep 17 00:00:00 2001 From: Ruben Westerberg Date: Sun, 6 Oct 2019 11:21:41 +1000 Subject: Added ch-1.pl --- challenge-028/ruben-westerberg/perl5/ch-1.pl | 29 ++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 challenge-028/ruben-westerberg/perl5/ch-1.pl diff --git a/challenge-028/ruben-westerberg/perl5/ch-1.pl b/challenge-028/ruben-westerberg/perl5/ch-1.pl new file mode 100755 index 0000000000..b545710959 --- /dev/null +++ b/challenge-028/ruben-westerberg/perl5/ch-1.pl @@ -0,0 +1,29 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use File::Basename; +my %ext; +while () { + s/(:?\s+)|(:?,)/ /g; + my @f=split(" "); + my $type= shift(@f) =~ /^text\// ? "text": "binary"; + $ext{$_}=$type for @f; +} +for (@ARGV) { + my ($filename, $dir, $suffix)=fileparse($_, qr/\.[^.]*/); + my $type=$ext{substr $suffix, 1}; + $type="binary" if ! $type; + print "$_: The file content is $type\n"; + + +} + +__DATA__ +text/html html htm shtml +text/css css +text/xml xml +text/mathml mml +text/plain txt +text/vnd.sun.j2me.app-descriptor jad +text/vnd.wap.wml wml +text/x-component htc -- cgit