aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-028/athanasius/perl5/ch-1.pl55
-rw-r--r--challenge-028/athanasius/perl5/ch-2.pl64
-rw-r--r--challenge-028/athanasius/perl6/ch-1.p656
-rw-r--r--challenge-028/athanasius/perl6/ch-2.p657
4 files changed, 232 insertions, 0 deletions
diff --git a/challenge-028/athanasius/perl5/ch-1.pl b/challenge-028/athanasius/perl5/ch-1.pl
new file mode 100644
index 0000000000..6071c94f2d
--- /dev/null
+++ b/challenge-028/athanasius/perl5/ch-1.pl
@@ -0,0 +1,55 @@
+#!perl
+
+################################################################################
+=comment
+
+Perl Weekly Challenge 028
+=========================
+
+Task #1
+-------
+Write a script to check the file content without actually 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.
+
+=cut
+################################################################################
+
+#--------------------------------------#
+# Copyright © 2019 PerlMonk Athanasius #
+#--------------------------------------#
+
+use strict;
+use warnings;
+use Const::Fast;
+
+const my $USAGE => "USAGE: perl $0 <Path>\n";
+
+BEGIN
+{
+ $| = 1;
+ print "\n";
+}
+
+#===============================================================================
+MAIN:
+#===============================================================================
+{
+ @ARGV == 0 and die $USAGE;
+ @ARGV > 1 and die "Too many command line arguments\n$USAGE";
+
+ $_ = $ARGV[0];
+
+ # See https://perldoc.perl.org/5.30.0/functions/-X.html
+
+ my $description = ! -e ? 'This does not exist' :
+ -d ? 'This is a directory' :
+ ! -f ? 'This is not a plain file' :
+ -z ? 'The file is empty' :
+ -T ? 'The file content is text' :
+ 'The file content is binary';
+
+ print qq{"$_": $description\n};
+}
+
+################################################################################
diff --git a/challenge-028/athanasius/perl5/ch-2.pl b/challenge-028/athanasius/perl5/ch-2.pl
new file mode 100644
index 0000000000..195730d8d0
--- /dev/null
+++ b/challenge-028/athanasius/perl5/ch-2.pl
@@ -0,0 +1,64 @@
+#!perl
+
+################################################################################
+=comment
+
+Perl Weekly Challenge 028
+=========================
+
+Task #2
+-------
+Write a script to display *Digital Clock*. Feel free to be as creative as you
+can when displaying digits. We expect bare minimum something like *"14:10:11"*.
+
+=cut
+################################################################################
+
+#--------------------------------------#
+# Copyright © 2019 PerlMonk Athanasius #
+#--------------------------------------#
+
+use strict;
+use warnings;
+use Const::Fast;
+use DateTime;
+
+const my $TIMEZONE => 'Australia/Brisbane';
+
+BEGIN
+{
+ $| = 1;
+ print "\n";
+}
+
+#===============================================================================
+MAIN:
+#===============================================================================
+{
+ my $dt = DateTime->now(time_zone => $TIMEZONE);
+ my $hour = $dt->hour; # 0-23
+ my $min = $dt->minute; # 0-59
+ my $sec = $dt->second; # 0-61 (leap seconds!)
+
+ printf "%02d:%02d:%02d\r", $hour, $min, $sec;
+
+ while (1)
+ {
+ sleep 1;
+
+ if (++$sec >= 60)
+ {
+ $sec = 0;
+
+ if (++$min == 60)
+ {
+ $min = 0;
+ $hour = 0 if ++$hour == 24;
+ }
+ }
+
+ printf "%02d:%02d:%02d\r", $hour, $min, $sec;
+ }
+}
+
+################################################################################
diff --git a/challenge-028/athanasius/perl6/ch-1.p6 b/challenge-028/athanasius/perl6/ch-1.p6
new file mode 100644
index 0000000000..8089a8a6eb
--- /dev/null
+++ b/challenge-028/athanasius/perl6/ch-1.p6
@@ -0,0 +1,56 @@
+use v6;
+
+################################################################################
+=begin comment
+
+Perl Weekly Challenge 028
+=========================
+
+Task #1
+-------
+Write a script to check the file content without actually 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.
+
+=end comment
+################################################################################
+
+#--------------------------------------#
+# Copyright © 2019 PerlMonk Athanasius #
+#--------------------------------------#
+
+use File::Util:from<Perl5> <file_type>;
+
+BEGIN say '';
+
+#===============================================================================
+sub MAIN(Str:D $path)
+#===============================================================================
+{
+ my Str $description = ! .e ?? 'This does not exist' !!
+ .d ?? 'This is a directory' !!
+ ! .f ?? 'This is not a plain file' !!
+ .z ?? 'The file is empty' !! 'OK'
+ given $path.IO;
+
+ if $description eq 'OK'
+ {
+ my Str @types = file_type($path);
+
+ if @types.elems == 2 && @types[0] eq 'PLAIN'
+ {
+ my Str $t1 = @types[1];
+ $description = $t1 eq 'TEXT' ?? 'The file content is text' !!
+ $t1 eq 'BINARY' ?? 'The file content is binary' !!
+ 'ERROR: The file content is neither text nor binary';
+ }
+ else
+ {
+ $description = 'ERROR: Unexpected file types: ' ~ @types.join(', ');
+ }
+ }
+
+ qq{"$path": $description}.say;
+}
+
+################################################################################
diff --git a/challenge-028/athanasius/perl6/ch-2.p6 b/challenge-028/athanasius/perl6/ch-2.p6
new file mode 100644
index 0000000000..81ad6ea713
--- /dev/null
+++ b/challenge-028/athanasius/perl6/ch-2.p6
@@ -0,0 +1,57 @@
+use v6;
+
+################################################################################
+=begin comment
+
+Perl Weekly Challenge 028
+=========================
+
+Task #2
+-------
+Write a script to display *Digital Clock*. Feel free to be as creative as you
+can when displaying digits. We expect bare minimum something like *"14:10:11"*.
+
+=end comment
+################################################################################
+
+#--------------------------------------#
+# Copyright © 2019 PerlMonk Athanasius #
+#--------------------------------------#
+
+my UInt constant $TIMEZONE = +10; # Difference in hours from UTC/GMT
+my UInt constant $SECS-PER-HOUR = 60 * 60;
+my UInt constant $TZ-OFFSET = $TIMEZONE * $SECS-PER-HOUR;
+
+BEGIN say '';
+
+#===============================================================================
+sub MAIN()
+#===============================================================================
+{
+ my DateTime $dt = DateTime.now(timezone => $TZ-OFFSET);
+ my UInt $hour = $dt.hour;
+ my UInt $min = $dt.minute;
+ my UInt $sec = $dt.whole-second;
+
+ "%02d:%02d:%02d\r".printf($hour, $min, $sec);
+
+ while 1
+ {
+ sleep 1;
+
+ if ++$sec >= 60
+ {
+ $sec = 0;
+
+ if ++$min == 60
+ {
+ $min = 0;
+ $hour = 0 if ++$hour == 24;
+ }
+ }
+
+ "%02d:%02d:%02d\r".printf($hour, $min, $sec);
+ }
+}
+
+################################################################################