aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-027/adam-russell/blog.txt1
-rw-r--r--challenge-027/adam-russell/perl5/Audit.pm37
-rw-r--r--challenge-027/adam-russell/perl5/ch-1.pl31
-rw-r--r--challenge-027/adam-russell/perl5/ch-2.pl21
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();