diff options
| -rw-r--r-- | challenge-160/luca-ferrari/postgresql/ch-1.plperl | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/challenge-160/luca-ferrari/postgresql/ch-1.plperl b/challenge-160/luca-ferrari/postgresql/ch-1.plperl new file mode 100644 index 0000000000..5cf81de25e --- /dev/null +++ b/challenge-160/luca-ferrari/postgresql/ch-1.plperl @@ -0,0 +1,45 @@ +-- Perl Weekly Challenge 160 +CREATE SCHEMA IF NOT EXISTS pwc160; +CREATE SCHEMA IF NOT EXISTS pwc160; + +/** + testdb=> select pwc160.four_is_magic( 7 ); + four_is_magic +--------------- + Seven is 5 + Five is 4 + Four is magic +*/ +CREATE OR REPLACE FUNCTION +pwc160.four_is_magic( int ) +RETURNS SETOF text +AS $CODE$ + +my $words = { + 1 => 'One', + 2 => 'Two', + 3 => 'Three', + 4 => 'Four', + 5 => 'Five', + 6 => 'Six', + 7 => 'Seven', + 8 => 'Eight', + 9 => 'Nine', +}; + + +my $stop = 4; +my ( $current ) = @_; + +while ( $current != $stop ) { + my $word = $words->{ $current }; + my $size = length $word; + $current = $size; + + return_next( "$word is $size" ); +} + +return_next( $words->{ $stop } . " is magic" ); +return undef; +$CODE$ +LANGUAGE plperl; |
