diff options
| author | andrezgz <andrezgz@gmail.com> | 2019-10-02 18:31:37 -0300 |
|---|---|---|
| committer | andrezgz <andrezgz@gmail.com> | 2019-10-02 18:31:37 -0300 |
| commit | 99aff44b68f23be51e7b1e2a1015455cc56b20c9 (patch) | |
| tree | e38af987f9bf87b2a82c4a3d224b127a08868957 | |
| parent | 24471e29acf4ae97bafcea95a12e2a05fe2d05f4 (diff) | |
| download | perlweeklychallenge-club-99aff44b68f23be51e7b1e2a1015455cc56b20c9.tar.gz perlweeklychallenge-club-99aff44b68f23be51e7b1e2a1015455cc56b20c9.tar.bz2 perlweeklychallenge-club-99aff44b68f23be51e7b1e2a1015455cc56b20c9.zip | |
challenge-028 andrezgz solution
| -rw-r--r-- | challenge-028/andrezgz/perl5/ch-1.pl | 26 | ||||
| -rw-r--r-- | challenge-028/andrezgz/perl5/ch-2.pl | 46 |
2 files changed, 72 insertions, 0 deletions
diff --git a/challenge-028/andrezgz/perl5/ch-1.pl b/challenge-028/andrezgz/perl5/ch-1.pl new file mode 100644 index 0000000000..bce6dc3479 --- /dev/null +++ b/challenge-028/andrezgz/perl5/ch-1.pl @@ -0,0 +1,26 @@ +#!/usr/bin/perl + +# https://perlweeklychallenge.org/blog/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. + +use strict; +use warnings; + +die "Usage: $0 <filename>" unless @ARGV == 1; + +my $file = shift; +die "'$file' is not a file" unless (-f $file ); + +# Maybe I'm cheating here because, being precise, +# the -T/-B test "reads" the first bytes of the file and then makes an educated guess + +print "The file content is ascii." if -T $file; +print "The file content is binary." if -B $file; + +__END__ + +./ch-1.pl ch-1.pl +The file content is ascii. diff --git a/challenge-028/andrezgz/perl5/ch-2.pl b/challenge-028/andrezgz/perl5/ch-2.pl new file mode 100644 index 0000000000..985ea3a96f --- /dev/null +++ b/challenge-028/andrezgz/perl5/ch-2.pl @@ -0,0 +1,46 @@ +#!/usr/bin/perl + +# https://perlweeklychallenge.org/blog/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". + +use strict; +use warnings; + +my @pattern = ( + '.... .......... ..................... ', + ': : :: : :: :: : :: :: :o', + ': : : :...: ..::..::...:... ::..::..: ', + ': : :: : : :: : :: : :o', + ':..: ::......: :...::..: ::..:...: ' + ); + +while (1) { + sleep 1; + system('clear'); #clear screen + + my ($s,$m,$h) = localtime(); + my @clock_components = split //, sprintf "%02d:%02d:%02d",$h,$m,$s; + + foreach my $p (@pattern) { # loop over each pattern line and + foreach my $c (@clock_components) { ## loop over each clock component + if ($c eq q{:}) { print substr $p, -1 } ### printing the pattern for : (last character of the line) + else { print substr $p, $c*4, 4 } ### or the corresponding one for the digit (4 characters each), + print q{ }; ### and after that, an empty space to complete the component + } ## + print qq{\n}; ## print a newline at the end of the line + } # + +} + +__END__ + +./ch-2.pl + + . . . . .... . . + :: : : o :: : : o :: :: + : : :..: : : : : : : : : + : : o : : : o : : + : : : :..: : : |
