diff options
| -rw-r--r-- | challenge-031/ruben-westerberg/README | 8 | ||||
| -rwxr-xr-x | challenge-031/ruben-westerberg/perl5/ch-1.pl | 8 | ||||
| -rwxr-xr-x | challenge-031/ruben-westerberg/perl5/ch-2.pl | 18 | ||||
| -rwxr-xr-x | challenge-031/ruben-westerberg/perl6/ch-1.p6 | 11 | ||||
| -rwxr-xr-x | challenge-031/ruben-westerberg/perl6/ch-2.p6 | 22 |
5 files changed, 64 insertions, 3 deletions
diff --git a/challenge-031/ruben-westerberg/README b/challenge-031/ruben-westerberg/README index 078e072f1a..2ca4621c32 100644 --- a/challenge-031/ruben-westerberg/README +++ b/challenge-031/ruben-westerberg/README @@ -2,9 +2,11 @@ Solution by Ruben Westerberg ch-1.pl and ch-1.p6 === -Run program to display all Sunday Xmas dates between years 2019 and 2100 - +Run the program with two command line arguments. First is the numerator, second is the denominator. Output will print successful result unless a divide by zero is detected. +If no arguments are provided numerator is set to 1 and denominator is set to 0 ch-2.pl and ch-2.p6 === -Run program to find all combinations of 3 number sequence which add to 12 and have at least 1 even number +Run the program with two arguments. The first is the name of ther variable to create and the second is the value to assign. +Output is the name and value of the dynamicaly named variable +If no arguments are given a random name and value are created; diff --git a/challenge-031/ruben-westerberg/perl5/ch-1.pl b/challenge-031/ruben-westerberg/perl5/ch-1.pl new file mode 100755 index 0000000000..6996d7c22b --- /dev/null +++ b/challenge-031/ruben-westerberg/perl5/ch-1.pl @@ -0,0 +1,8 @@ +#!/usr/bin/env perl +use feature qw<say>; +my $numerator=$ARGV[0]//1; +my $denominator=$ARGV[1]//0; +my $result=eval {$numerator/$denominator}; +say "Division ok: $numerator/$denominator = $result" if defined $result; +say "Division failed: divide by zero" if !defined $result; + diff --git a/challenge-031/ruben-westerberg/perl5/ch-2.pl b/challenge-031/ruben-westerberg/perl5/ch-2.pl new file mode 100755 index 0000000000..4d3b199d42 --- /dev/null +++ b/challenge-031/ruben-westerberg/perl5/ch-2.pl @@ -0,0 +1,18 @@ +#!/usr/bin/env perl +use feature qw<say>; +my $name=$ARGV[0]// "var".rand; +my $value=$ARGV[1]//rand; + +{ + say "Using symbolic refs"; + no strict refs; + $$name=$value; + say "Variable name: $name Value: ${$name}"; +} +print "\n"; +{ + say "Using a hash"; + my %h; + $h{$name}=$value; + say "Variable name: $name Value: $h{$name}"; +} diff --git a/challenge-031/ruben-westerberg/perl6/ch-1.p6 b/challenge-031/ruben-westerberg/perl6/ch-1.p6 new file mode 100755 index 0000000000..a1410d6256 --- /dev/null +++ b/challenge-031/ruben-westerberg/perl6/ch-1.p6 @@ -0,0 +1,11 @@ +#!/usr/bin/env perl6 + +my $numerator=@*ARGS[0]//1; +my $denominator=@*ARGS[1]//0; +my $result; + +try $result=($numerator/$denominator).Str; + +put "Division ok: $numerator/$denominator = $result" unless $!; +put "Division failed: Divide by zero" if $!; + diff --git a/challenge-031/ruben-westerberg/perl6/ch-2.p6 b/challenge-031/ruben-westerberg/perl6/ch-2.p6 new file mode 100755 index 0000000000..f4ea55d641 --- /dev/null +++ b/challenge-031/ruben-westerberg/perl6/ch-2.p6 @@ -0,0 +1,22 @@ +#!/usr/bin/env perl6 +use MONKEY-SEE-NO-EVAL; +my $name=@*ARGS[0]//"var"~1000.rand.Int; +my $value=@*ARGS[1]//1.rand; +{ + put "Using Module/eval"; + module D { + EVAL "our \$$name=\"$value\""; + } + put $D::($name); + put "Variable name: $name Value: {$D::($name)}"; +} + +put ""; + +{ + put "Using Hash"; + my %h; + %h{$name}=$value; + put "Variable name: $name Value: %h{$name}"; + +} |
