aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2019-09-28 04:36:23 +0100
committerGitHub <noreply@github.com>2019-09-28 04:36:23 +0100
commit48a4ed8d49b7e8d468d4bfd70d72e27c69b5b0d5 (patch)
treef57c3cac82501fa0081dba71841f7f6a96fc4c6e
parent383eb02731cdd702a7dd410326681b2bf9f380fa (diff)
parent8b17faf74310bc46d67617468928ede6fa17c271 (diff)
downloadperlweeklychallenge-club-48a4ed8d49b7e8d468d4bfd70d72e27c69b5b0d5.tar.gz
perlweeklychallenge-club-48a4ed8d49b7e8d468d4bfd70d72e27c69b5b0d5.tar.bz2
perlweeklychallenge-club-48a4ed8d49b7e8d468d4bfd70d72e27c69b5b0d5.zip
Merge pull request #671 from Doomtrain14/master
Added Perl5 solution for task#2
-rw-r--r--challenge-027/yet-ebreo/perl5/ch-1.pl1
-rw-r--r--challenge-027/yet-ebreo/perl5/ch-2.pl44
2 files changed, 44 insertions, 1 deletions
diff --git a/challenge-027/yet-ebreo/perl5/ch-1.pl b/challenge-027/yet-ebreo/perl5/ch-1.pl
index a8659559fd..de535cfb25 100644
--- a/challenge-027/yet-ebreo/perl5/ch-1.pl
+++ b/challenge-027/yet-ebreo/perl5/ch-1.pl
@@ -9,7 +9,6 @@ use v5.10;
die "Usage:\n\tch-1.pl <X11> <Y11> <X12> <Y12> <X21> <Y21> <X22> <Y22>\n\n" if @ARGV != 8;
-# one intersection point
my @line1 = ([$ARGV[0],$ARGV[1]],[$ARGV[2],$ARGV[3]]);
my @line2 = ([$ARGV[4],$ARGV[5]],[$ARGV[6],$ARGV[7]]);
my $y_intercept1 = 0;
diff --git a/challenge-027/yet-ebreo/perl5/ch-2.pl b/challenge-027/yet-ebreo/perl5/ch-2.pl
new file mode 100644
index 0000000000..963283d8f8
--- /dev/null
+++ b/challenge-027/yet-ebreo/perl5/ch-2.pl
@@ -0,0 +1,44 @@
+# Write a script that allows you to capture/display historical data. It could be an object or a scalar. For example
+# my $x = 10; $x = 20; $x -= 5;
+# After the above operations, it should list $x historical value in order.
+
+use strict;
+use warnings;
+use v5.10;
+
+package hist;
+
+sub TIESCALAR {
+ my $class = shift;
+ my $this = [];
+ bless $this, $class;
+ return $this;
+}
+
+sub STORE {
+ push @{ $_[0] }, $_[1];
+}
+sub FETCH {
+ return $_[0][-1];
+}
+
+sub GETHIST {
+ return @{ $_[0] };
+}
+1;
+
+package main;
+use Data::Dumper;
+
+my $obj = tie my $x, "hist";
+
+$x = 10;
+$x = 20;
+$x -= 5;
+$x = 3.1416;
+$x = [qw(a quick brown fox jumps over the lazy dog)];
+$x = 1e3;
+$x*= sqrt 3;
+
+print Dumper($obj->GETHIST());
+