aboutsummaryrefslogtreecommitdiff
path: root/challenge-029
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2019-10-16 20:47:40 +0100
committerGitHub <noreply@github.com>2019-10-16 20:47:40 +0100
commit491777c26ea493a32abb5207cb8bbce05e7d9e4a (patch)
treecdb8cdc71352385ca282525a63601768e49cc9fe /challenge-029
parent55c19b3f941434c754217b616714ff5f7806539e (diff)
parenta8f12f4537b3adda7488f3bf40ee389d0eac27b7 (diff)
downloadperlweeklychallenge-club-491777c26ea493a32abb5207cb8bbce05e7d9e4a.tar.gz
perlweeklychallenge-club-491777c26ea493a32abb5207cb8bbce05e7d9e4a.tar.bz2
perlweeklychallenge-club-491777c26ea493a32abb5207cb8bbce05e7d9e4a.zip
Merge pull request #788 from jaldhar/challenge-029
Challenge 29 by Jaldhar H. Vyas
Diffstat (limited to 'challenge-029')
-rw-r--r--challenge-029/jaldhar-h-vyas/blog.txt1
-rw-r--r--challenge-029/jaldhar-h-vyas/c/Makefile17
-rw-r--r--challenge-029/jaldhar-h-vyas/c/hello.c6
-rw-r--r--challenge-029/jaldhar-h-vyas/c/hello.h6
-rw-r--r--challenge-029/jaldhar-h-vyas/perl5/Hello.i11
-rw-r--r--challenge-029/jaldhar-h-vyas/perl5/Makefile20
-rwxr-xr-xchallenge-029/jaldhar-h-vyas/perl5/ch-1.pl16
-rwxr-xr-xchallenge-029/jaldhar-h-vyas/perl5/ch-2.pl17
-rw-r--r--challenge-029/jaldhar-h-vyas/perl6/Hello.pm610
-rwxr-xr-xchallenge-029/jaldhar-h-vyas/perl6/ch-1.p615
-rwxr-xr-xchallenge-029/jaldhar-h-vyas/perl6/ch-2.p613
11 files changed, 132 insertions, 0 deletions
diff --git a/challenge-029/jaldhar-h-vyas/blog.txt b/challenge-029/jaldhar-h-vyas/blog.txt
new file mode 100644
index 0000000000..2969c3a887
--- /dev/null
+++ b/challenge-029/jaldhar-h-vyas/blog.txt
@@ -0,0 +1 @@
+https://www.braincells.com/perl/2019/10/perl_weekly_challenge_week_29.html \ No newline at end of file
diff --git a/challenge-029/jaldhar-h-vyas/c/Makefile b/challenge-029/jaldhar-h-vyas/c/Makefile
new file mode 100644
index 0000000000..804be4831e
--- /dev/null
+++ b/challenge-029/jaldhar-h-vyas/c/Makefile
@@ -0,0 +1,17 @@
+
+CC?=cc
+CFLAGS:=-O2 -Wall -Wextra -D_REENTRANT -fpic -I.
+PROG=libhello.so
+
+$(PROG): hello.o
+ $(CC) -shared -Wl,-soname,$(PROG) $^ -o $@
+
+hello.o: hello.c
+ $(CC) $(CFLAGS) -c -o $@ $<
+
+hello.c: hello.h
+
+clean:
+ -rm *.o $(PROG)
+
+.PHONY: clean
diff --git a/challenge-029/jaldhar-h-vyas/c/hello.c b/challenge-029/jaldhar-h-vyas/c/hello.c
new file mode 100644
index 0000000000..aeb20bf942
--- /dev/null
+++ b/challenge-029/jaldhar-h-vyas/c/hello.c
@@ -0,0 +1,6 @@
+#include <stdio.h>
+#include "hello.h"
+
+void hello() {
+ puts("Hello world!");
+} \ No newline at end of file
diff --git a/challenge-029/jaldhar-h-vyas/c/hello.h b/challenge-029/jaldhar-h-vyas/c/hello.h
new file mode 100644
index 0000000000..e37900c745
--- /dev/null
+++ b/challenge-029/jaldhar-h-vyas/c/hello.h
@@ -0,0 +1,6 @@
+#ifndef _HELLO_H_
+#define _HELLO_H_
+
+void hello();
+
+#endif
diff --git a/challenge-029/jaldhar-h-vyas/perl5/Hello.i b/challenge-029/jaldhar-h-vyas/perl5/Hello.i
new file mode 100644
index 0000000000..050d2387f6
--- /dev/null
+++ b/challenge-029/jaldhar-h-vyas/perl5/Hello.i
@@ -0,0 +1,11 @@
+%module Hello
+
+%{
+ #include "hello.h"
+%}
+
+void hello();
+
+%perlcode %{
+ @EXPORT = qw( hello );
+%} \ No newline at end of file
diff --git a/challenge-029/jaldhar-h-vyas/perl5/Makefile b/challenge-029/jaldhar-h-vyas/perl5/Makefile
new file mode 100644
index 0000000000..e355d1e238
--- /dev/null
+++ b/challenge-029/jaldhar-h-vyas/perl5/Makefile
@@ -0,0 +1,20 @@
+CC?=cc
+PERLCFLAGS:=$(shell perl -MConfig -e'print join q{ }, @Config{qw(ccflags optimize cccdlflags)};' )
+PERLINC:=$(shell perl -MConfig -e'print "$$Config{archlib}/CORE";')
+LIBHELLO:=../c
+CFLAGS:=$(PERLCFLAGS) -I$(PERLINC) -I$(LIBHELLO)
+LDFLAGS:=-L$(LIBHELLO) -lhello -Xlinker -rpath $(LIBHELLO)
+
+Hello.so: Hello_wrap.o
+ $(CC) -shared $^ $(LDFLAGS) -o $@
+
+Hello_wrap.o: Hello_wrap.c
+ $(CC) $(CFLAGS) -c -o $@ $<
+
+Hello_wrap.c: Hello.i
+ swig -perl $<
+
+clean:
+ -rm Hello_wrap.c Hello.pm *.o Hello.so
+
+.PHONY: clean
diff --git a/challenge-029/jaldhar-h-vyas/perl5/ch-1.pl b/challenge-029/jaldhar-h-vyas/perl5/ch-1.pl
new file mode 100755
index 0000000000..a430621ab7
--- /dev/null
+++ b/challenge-029/jaldhar-h-vyas/perl5/ch-1.pl
@@ -0,0 +1,16 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use 5.010;
+
+sub expand {
+ my ($string) = @_;
+ $string =~ / \{(.+)\} /msx;
+
+ return map {
+ (my $expansion = $string) =~ s/\{(.+)\}/$_/msx;
+ $expansion;
+ } split /,\s*/, $1;
+}
+
+say for expand($ARGV[0] // q{}); \ No newline at end of file
diff --git a/challenge-029/jaldhar-h-vyas/perl5/ch-2.pl b/challenge-029/jaldhar-h-vyas/perl5/ch-2.pl
new file mode 100755
index 0000000000..a45ff1ddb9
--- /dev/null
+++ b/challenge-029/jaldhar-h-vyas/perl5/ch-2.pl
@@ -0,0 +1,17 @@
+#!/usr/bin/perl
+
+# To run this script:
+#
+# $ cd ../c
+# $ make
+# $ cd ../perl5
+# $ make
+# ./ch-2.pl
+
+use warnings;
+use strict;
+use 5.010;
+use lib qw( . );
+use Hello;
+
+hello(); \ No newline at end of file
diff --git a/challenge-029/jaldhar-h-vyas/perl6/Hello.pm6 b/challenge-029/jaldhar-h-vyas/perl6/Hello.pm6
new file mode 100644
index 0000000000..9d243c1849
--- /dev/null
+++ b/challenge-029/jaldhar-h-vyas/perl6/Hello.pm6
@@ -0,0 +1,10 @@
+use v6;
+unit module Hello;
+
+use NativeCall;
+
+sub libhello is export {
+ return '../c/libhello.so';
+}
+
+sub hello() is native(&libhello) is export {*};
diff --git a/challenge-029/jaldhar-h-vyas/perl6/ch-1.p6 b/challenge-029/jaldhar-h-vyas/perl6/ch-1.p6
new file mode 100755
index 0000000000..a450436c84
--- /dev/null
+++ b/challenge-029/jaldhar-h-vyas/perl6/ch-1.p6
@@ -0,0 +1,15 @@
+#!/usr/bin/perl6
+
+sub expand(Str $string) {
+ $string ~~ / \{(.+)\} /;
+
+ return $0.split(/\,\s*/).map({
+ my $word = $_;
+ (my $expansion = $string) ~~ s/\{.+\}/$word/;
+ $expansion;
+ });
+}
+
+sub MAIN(Str $string) {
+ .say for expand($string);
+} \ No newline at end of file
diff --git a/challenge-029/jaldhar-h-vyas/perl6/ch-2.p6 b/challenge-029/jaldhar-h-vyas/perl6/ch-2.p6
new file mode 100755
index 0000000000..0e80c83430
--- /dev/null
+++ b/challenge-029/jaldhar-h-vyas/perl6/ch-2.p6
@@ -0,0 +1,13 @@
+#!/usr/bin/perl6
+
+# To run this script:
+#
+# $ cd ../c
+# $ make
+# $ cd ../perl6
+# ./ch-2.p6
+
+use lib '.';
+use Hello;
+
+hello(); \ No newline at end of file