diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2019-09-30 19:10:19 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-09-30 19:10:19 +0100 |
| commit | cd259c673981034408fb57c3fa632be5b14ad6bc (patch) | |
| tree | 3a5fbc0f235cd6d867e9fa2d5bd486a59179cb17 | |
| parent | b2637625e53455d9a11c053853eaf49554a1c10d (diff) | |
| parent | 1a789f6e760c60c81fabb8fe3dbf9fc4ced0542e (diff) | |
| download | perlweeklychallenge-club-cd259c673981034408fb57c3fa632be5b14ad6bc.tar.gz perlweeklychallenge-club-cd259c673981034408fb57c3fa632be5b14ad6bc.tar.bz2 perlweeklychallenge-club-cd259c673981034408fb57c3fa632be5b14ad6bc.zip | |
Merge pull request #689 from duanepowell/pwc28
Commit solutions for perl weekly challenge 028
| -rwxr-xr-x | challenge-028/duane-powell/perl5/ch-1.pl | 33 | ||||
| -rwxr-xr-x | challenge-028/duane-powell/perl5/ch-2.pl | 205 |
2 files changed, 238 insertions, 0 deletions
diff --git a/challenge-028/duane-powell/perl5/ch-1.pl b/challenge-028/duane-powell/perl5/ch-1.pl new file mode 100755 index 0000000000..bba5f6d7e9 --- /dev/null +++ b/challenge-028/duane-powell/perl5/ch-1.pl @@ -0,0 +1,33 @@ +#!/usr/bin/perl +use Modern::Perl; + +# 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. + +my $file = shift; +if ($file) { + if (-e $file) { + say "The file $file content is binary" if (-B $file); + say "The file $file content is ascii" if (-T $file); + } else { + say "The file $file does not exist"; + } +} else { + say "Usage: $0 filename"; +} + +__END__ + +./ch-1.pl +Usage: ./ch-1.pl filename + +./ch-1.pl filename +The file filename does not exist + +./ch-1.pl ch-2.pl +The file ch-2.pl content is ascii + +./ch-1.pl /tmp/data.tgz +The file /tmp/data.tgz content is binary + diff --git a/challenge-028/duane-powell/perl5/ch-2.pl b/challenge-028/duane-powell/perl5/ch-2.pl new file mode 100755 index 0000000000..94eda2a2c7 --- /dev/null +++ b/challenge-028/duane-powell/perl5/ch-2.pl @@ -0,0 +1,205 @@ +#!/usr/bin/perl +use Modern::Perl; +use Term::ANSIColor; + +# 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 + +my $color = shift || 'red'; +usage() unless $color =~ m/^(black|red|green|yellow|blue|magenta|cyan|white)$/; + +my @ascii_art; +push @ascii_art, sub { +" + ____ +| | +| | +| | +| | +| | + ____ +" +}; +push @ascii_art, sub { +" + + | + | + | + | + | + | +" +}; +push @ascii_art, sub { +" + ____ + | + | + ____ +| +| + ____ +" +}; +push @ascii_art, sub { +" + ____ + | + | + ____ + | + | + ____ +" +}; +push @ascii_art, sub { +" + +| | +| | + ____ + | + | + | +" +}; +push @ascii_art, sub { +" + ____ +| +| + ____ + | + | + ____ +" +}; +push @ascii_art, sub { +" + +| +| + ____ +| | +| | + ____ +" +}; +push @ascii_art, sub { +" + ____ + | + | + | + | + | + | +" +}; +push @ascii_art, sub { +" + ____ +| | +| | + ____ +| | +| | + ____ +" +}; + +push @ascii_art, sub { +" + ____ +| | +| | + ____ + | + | + | +" +}; + +my $COLON = 10; +push @ascii_art, sub { +# @{$ascii_art[$COLON]} returns a colon : +" + + + o + + + o + +" +}; + +print color ($color); +while (1) { + sleep 1; + my ($s,$m,$h,undef,undef,undef,undef,undef) = localtime(time); + my ($h1, $h2) = split(//,sprintf("%02d", $h)); + my ($m1, $m2) = split(//,sprintf("%02d", $m)); + my ($s1, $s2) = split(//,sprintf("%02d", $s)); + my @out; + foreach (&{$ascii_art[$h1]},&{$ascii_art[$h2]}, &{$ascii_art[$COLON]}, + &{$ascii_art[$m1]},&{$ascii_art[$m2]}, &{$ascii_art[$COLON]}, + &{$ascii_art[$s1]},&{$ascii_art[$s2]}) { + push @out, split("\n",$_); + } + # Each digit in the clock interface is 8 lines of text + # 6 digits and 2 colons totals to 64 lines of output, @out, a 1 x 64 array + # We need to convert to an 8 x 8 array, @clock, to print horizontally + # From this: 1 x 64 + # 1 + # 2 + # : + # 0 + # 1 + # : + # 0 + # 1 + # To this: 8 x 8 + # 12:01:01 + + my @clock; + foreach (0..63) { + $clock[0] .= $out[$_] if ($_ % 8 == 0); + $clock[1] .= $out[$_] if ($_ % 8 == 1); + $clock[2] .= $out[$_] if ($_ % 8 == 2); + $clock[3] .= $out[$_] if ($_ % 8 == 3); + $clock[4] .= $out[$_] if ($_ % 8 == 4); + $clock[5] .= $out[$_] if ($_ % 8 == 5); + $clock[6] .= $out[$_] if ($_ % 8 == 6); + $clock[7] .= $out[$_] if ($_ % 8 == 7); + } + + system("clear"); + say $_ foreach (@clock); +} +print color('reset'); +exit; + +sub usage { + print <<EOU; +$0 black|red|green|yellow|blue|magenta|cyan|white +Displays ticking digital clock, make a wish at 11:11:11 +EOU + exit; +} + +__END__ + + +./ch-2.pl white + + ____ ____ ____ + | | || | | | | + | | o || | o| | | + | ____ ____ ____ ____ ____ + || | | | | + || o | | o | | + | ____ ____ | ____ | + + |
