diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2019-10-06 12:04:26 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2019-10-06 12:04:26 +0100 |
| commit | efd420c53b9f744c6ad5837e4b020cc6258a0913 (patch) | |
| tree | f222ea0555815e66400d46b6023d7b63bb474af5 | |
| parent | 13c93772c13ff779d42566c1b1b5613d9e82e4df (diff) | |
| parent | d4998617d10c7d70a6fb4a581891fbd95a5e5466 (diff) | |
| download | perlweeklychallenge-club-efd420c53b9f744c6ad5837e4b020cc6258a0913.tar.gz perlweeklychallenge-club-efd420c53b9f744c6ad5837e4b020cc6258a0913.tar.bz2 perlweeklychallenge-club-efd420c53b9f744c6ad5837e4b020cc6258a0913.zip | |
Merge branch 'master' of https://github.com/manwar/perlweeklychallenge-club
| -rw-r--r-- | challenge-028/ruben-westerberg/README | 9 | ||||
| -rwxr-xr-x | challenge-028/ruben-westerberg/perl5/ch-1.pl | 29 | ||||
| -rwxr-xr-x | challenge-028/ruben-westerberg/perl5/ch-2.pl | 20 | ||||
| -rwxr-xr-x | challenge-028/ruben-westerberg/perl6/ch-1.p6 | 27 | ||||
| -rwxr-xr-x | challenge-028/ruben-westerberg/perl6/ch-2.p6 | 16 |
5 files changed, 94 insertions, 7 deletions
diff --git a/challenge-028/ruben-westerberg/README b/challenge-028/ruben-westerberg/README index c17b59a016..aa0fd9c8d2 100644 --- a/challenge-028/ruben-westerberg/README +++ b/challenge-028/ruben-westerberg/README @@ -2,14 +2,9 @@ Solution by Ruben Westerberg ch-1.pl and ch-1.p6 === -Intersecting lines. -Run the program. you will be propted to enter two points for the first line and then two points for the second line. -Points are intered as interleved xy pairs -example: - When prompted to enter the line starting at the origin and ending at x=5 and y=10, the two points are entered as follows: - 0 0 5 10 +Run the program with command line arguments representing file names. The extension of the file name is matched against known file types. ch-2.pl and ch-2.p6 === -Run the program to demonstrate history of every assignement to a variable. +Run the program to show a simple digital clock 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 (<DATA>) { + 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 diff --git a/challenge-028/ruben-westerberg/perl5/ch-2.pl b/challenge-028/ruben-westerberg/perl5/ch-2.pl new file mode 100755 index 0000000000..b018117250 --- /dev/null +++ b/challenge-028/ruben-westerberg/perl5/ch-2.pl @@ -0,0 +1,20 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Time::HiRes qw<usleep>; +use POSIX qw<strftime>; +use v5.26; +$|=1; +while (1) { + state $c=0; + if (($c++ % 10) == 0) { + print "\x1b[2K"; + print "\x1b[1000D"; + print strftime "%H:%M:%S", localtime; + } + usleep 100000;; + print "="; + +} + + diff --git a/challenge-028/ruben-westerberg/perl6/ch-1.p6 b/challenge-028/ruben-westerberg/perl6/ch-1.p6 new file mode 100755 index 0000000000..483d39f282 --- /dev/null +++ b/challenge-028/ruben-westerberg/perl6/ch-1.p6 @@ -0,0 +1,27 @@ +#!/usr/bin/env perl6 +my %ext; +data.lines.map({ + my @f=.split(/\s|\,/,:skip-empty); + my $type= /^text\// ?? "text" !! "binary" given @f.shift; + %ext{$_}=$type for @f; +}); + +@*ARGS.map({ + my $type=%ext{.IO.extension}; + $type="binary" if !$type; + put "$_: The file content is $type"; +}); + +#emulate perl5 DATA section... sort of.. +sub data() { + q:to/END/ + 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 + END +} diff --git a/challenge-028/ruben-westerberg/perl6/ch-2.p6 b/challenge-028/ruben-westerberg/perl6/ch-2.p6 new file mode 100755 index 0000000000..d58aa21261 --- /dev/null +++ b/challenge-028/ruben-westerberg/perl6/ch-2.p6 @@ -0,0 +1,16 @@ +#!/usr/bin/env perl6 +my $offset=0; +#my @codes=("\x1b[{$offset}D" +react { whenever Supply.interval(.1) { + print "="; +} + whenever Supply.interval(1) { + print "\x1b[2K"; + print "\x1b[1000D"; + print DateTime.now.hh-mm-ss; + } +} + + + + |
