diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2019-09-29 21:35:50 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-09-29 21:35:50 +0100 |
| commit | 90c8d9a52b83422a214d41f36752df5d99e59753 (patch) | |
| tree | bc693cce219bbb3409a11c43f9cba82929862d6f | |
| parent | a992c9b230b68f2fce5e0c69b4a2d95f2c99e33f (diff) | |
| parent | 23ae84ea0cdc089535a857109c8f38619d4ffcb9 (diff) | |
| download | perlweeklychallenge-club-90c8d9a52b83422a214d41f36752df5d99e59753.tar.gz perlweeklychallenge-club-90c8d9a52b83422a214d41f36752df5d99e59753.tar.bz2 perlweeklychallenge-club-90c8d9a52b83422a214d41f36752df5d99e59753.zip | |
Merge pull request #684 from adamcrussell/challenge-027
Challenge 027
| -rw-r--r-- | challenge-027/adam-russell/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-027/adam-russell/perl5/Audit.pm | 37 | ||||
| -rw-r--r-- | challenge-027/adam-russell/perl5/ch-1.pl | 31 | ||||
| -rw-r--r-- | challenge-027/adam-russell/perl5/ch-2.pl | 21 |
4 files changed, 90 insertions, 0 deletions
diff --git a/challenge-027/adam-russell/blog.txt b/challenge-027/adam-russell/blog.txt new file mode 100644 index 0000000000..09b3105dab --- /dev/null +++ b/challenge-027/adam-russell/blog.txt @@ -0,0 +1 @@ +https://adamcrussell.livejournal.com/9508.html diff --git a/challenge-027/adam-russell/perl5/Audit.pm b/challenge-027/adam-russell/perl5/Audit.pm new file mode 100644 index 0000000000..c1d8354213 --- /dev/null +++ b/challenge-027/adam-russell/perl5/Audit.pm @@ -0,0 +1,37 @@ +package Audit{ + use Data::Dump q/pp/; + use Filter::Simple; + + our %Log; + + sub audit{ + my($name, $value) = @_; + $value = "undef" if !defined($value); + if($Log{$name}){ + push @{$Log{$name}}, $value; + } + else{ + $Log{$name} = [$value]; + } + } + + sub clear_log{ + %Log = (); + } + + sub print_log{ + for my $key (keys %Log){ + print "$key: " . join(", ", @{$Log{$key}}) . "\n"; + } + } + + sub pretty_print_log{ + for my $key (keys %Log){ + print "$key: " . join(", ", map{ pp $_ } @{$Log{$key}}) . "\n"; + } + } + + FILTER_ONLY code => sub{ + s|((\$[[:alnum:]_]*).*;)|$1 Audit::audit('$2', $2);|g; + } +} diff --git a/challenge-027/adam-russell/perl5/ch-1.pl b/challenge-027/adam-russell/perl5/ch-1.pl new file mode 100644 index 0000000000..f5cdf4895c --- /dev/null +++ b/challenge-027/adam-russell/perl5/ch-1.pl @@ -0,0 +1,31 @@ +use strict; +use warnings; +## +# Write a script to find the intersection of two straight lines. +# The co-ordinates of the two lines should be provided as command line parameters. +## +MAIN:{ + my @endpoints_line_0 = @ARGV[0, 1]; + my @endpoints_line_1 = @ARGV[2, 3]; + @endpoints_line_0 = map { $_=~tr/()//d; [split(/,/, $_)];} @endpoints_line_0; + @endpoints_line_1 = map { $_=~tr/()//d; [split(/,/, $_)];} @endpoints_line_1; + my($a, $b, $c, $d, $p, $q, $r, $s) = ( + $endpoints_line_0[0]->[0], + $endpoints_line_0[0]->[1], + $endpoints_line_0[1]->[0], + $endpoints_line_0[1]->[1], + $endpoints_line_1[0]->[0], + $endpoints_line_1[0]->[1], + $endpoints_line_1[1]->[0], + $endpoints_line_1[1]->[1] + ); + my $denominator = ($c - $a) * ($s - $q) - ($r - $p) * ($c - $b); + + my $x0 = ($c * $b - $a * $d) * ($r - $p) - ($r * $q - $p * $s) * ($c - $a); + my $y0 = ($c * $b - $a * $d) * ($s - $q) - ($r * $q - $p * $s) * ($d - $b); + + my $x = $x0/$denominator; + my $y = $y0/$denominator; + + print "($a, $b)--($c, $d) and ($p, $q)--($r, $s) intersect at ($x, $y)\n"; +} diff --git a/challenge-027/adam-russell/perl5/ch-2.pl b/challenge-027/adam-russell/perl5/ch-2.pl new file mode 100644 index 0000000000..8ebf38a6ee --- /dev/null +++ b/challenge-027/adam-russell/perl5/ch-2.pl @@ -0,0 +1,21 @@ +use strict; +use warnings; +## +# Write a script that allows you to capture/display historical data. +# It could be an object or a scalar. +## +use Audit; +use Class::Hash; + +my $test0; +$test0 = 2; +$test0 = 3; + +Audit::print_log(); +Audit::clear_log(); + +my $test1 = new Class::Hash(A => "B"); +$test1 = new Class::Hash(B => "C"); +$test1 = new Class::Hash(C => "D"); +#Audit::pretty_print_log(); +Audit::print_log(); |
