From c9b06033cc830ad98c41f599d770c4707ec51b39 Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Mon, 6 Mar 2023 14:27:32 +0100 Subject: Task 1 plperl done --- challenge-207/luca-ferrari/postgresql/ch-1.plperl | 34 +++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 challenge-207/luca-ferrari/postgresql/ch-1.plperl diff --git a/challenge-207/luca-ferrari/postgresql/ch-1.plperl b/challenge-207/luca-ferrari/postgresql/ch-1.plperl new file mode 100644 index 0000000000..f40c97ae1e --- /dev/null +++ b/challenge-207/luca-ferrari/postgresql/ch-1.plperl @@ -0,0 +1,34 @@ +-- +-- Perl Weekly Challenge 207 +-- Task 1 +-- See +-- + +CREATE SCHEMA IF NOT EXISTS pwc207; + +CREATE OR REPLACE FUNCTION +pwc207.task1_plperl( text[] ) +RETURNS SETOF text +AS $CODE$ + + my ( $words ) = @_; + my ( @keyboard ) = qw/ qwertyuiop asdfghjkl zxcvbnm /; + + for my $current_word ( $words->@* ) { + for my $current_row ( @keyboard ) { + my $found = 0; + for my $current_letter ( split( '', lc( $current_word ) ) ) { + $found++ if ( $current_row =~ /$current_letter/ ); + } + + if ( scalar( split( '', $current_word ) ) == $found ) { + return_next( $current_word ); + last; + } + } + } + + return undef; + +$CODE$ +LANGUAGE plperl; -- cgit