aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2019-10-06 12:10:52 +0100
committerGitHub <noreply@github.com>2019-10-06 12:10:52 +0100
commita795a64d6896f8bf042924533fa8c90eae4c8082 (patch)
tree63e409d5daa7407815fc2e05503801a489c4fc90
parentf03908193b5db84d26f17feab88e4da1c4f363d8 (diff)
parent5945392672d6c3351b08c87a09f22d5df4060189 (diff)
downloadperlweeklychallenge-club-a795a64d6896f8bf042924533fa8c90eae4c8082.tar.gz
perlweeklychallenge-club-a795a64d6896f8bf042924533fa8c90eae4c8082.tar.bz2
perlweeklychallenge-club-a795a64d6896f8bf042924533fa8c90eae4c8082.zip
Merge pull request #722 from adamcrussell/challenge-028
solution for challenge 028
-rw-r--r--challenge-028/adam-russell/blog.txt1
-rw-r--r--challenge-028/adam-russell/perl5/ch-1.pl19
-rw-r--r--challenge-028/adam-russell/perl5/ch-2.pl40
3 files changed, 60 insertions, 0 deletions
diff --git a/challenge-028/adam-russell/blog.txt b/challenge-028/adam-russell/blog.txt
new file mode 100644
index 0000000000..eaf07546b3
--- /dev/null
+++ b/challenge-028/adam-russell/blog.txt
@@ -0,0 +1 @@
+https://adamcrussell.livejournal.com/9784.html
diff --git a/challenge-028/adam-russell/perl5/ch-1.pl b/challenge-028/adam-russell/perl5/ch-1.pl
new file mode 100644
index 0000000000..b8da076c7d
--- /dev/null
+++ b/challenge-028/adam-russell/perl5/ch-1.pl
@@ -0,0 +1,19 @@
+use strict;
+use warnings;
+##
+# 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 File::MMagic;
+use constant TEXT_TYPE => "The file content is ascii.";
+use constant BINARY_TYPE => "The file content is binary.";
+
+my $fm = new File::MMagic();
+my $type = $fm->checktype_filename($ARGV[0]);
+if($type=~m/text\//){
+ print TEXT_TYPE . "\n";
+}
+else{
+ print BINARY_TYPE . "\n";
+}
diff --git a/challenge-028/adam-russell/perl5/ch-2.pl b/challenge-028/adam-russell/perl5/ch-2.pl
new file mode 100644
index 0000000000..0f817d68e1
--- /dev/null
+++ b/challenge-028/adam-russell/perl5/ch-2.pl
@@ -0,0 +1,40 @@
+use strict;
+use warnings;
+##
+# Write a script to display a digital clock.
+##
+use boolean;
+use English;
+use DateTime::Set;
+use POE q/Component::Schedule/;
+
+$OUTPUT_AUTOFLUSH = true;
+
+sub update_clock{
+ my $d = DateTime->now();
+ $d->set_time_zone("America/New_York");
+ print "\b" x 8;
+ print "\x1b[93;47m" .
+ sprintf("%02d", $d->hour) . ":" .
+ sprintf("%02d", $d->minute) . ":" .
+ sprintf("%02d", $d->second) .
+ "\x1b[0m";
+}
+
+POE::Session->create(
+ inline_states => {
+ _start => sub {
+ $_[HEAP]{schedule} = POE::Component::Schedule->add(
+ $_[SESSION], on_tick => DateTime::Set->from_recurrence(
+ after => DateTime->now,
+ recurrence => sub{
+ return $_[0]->truncate(to=>"second")->add(seconds => 1)
+ },
+ ),
+ );
+ },
+ on_tick => \&update_clock,
+ },
+);
+
+POE::Kernel->run();