diff options
| author | Dave Jacoby <jacoby.david@gmail.com> | 2019-10-08 15:40:22 -0400 |
|---|---|---|
| committer | Dave Jacoby <jacoby.david@gmail.com> | 2019-10-08 15:40:22 -0400 |
| commit | d3ac4cea33e2d802775b8d5b13c2e87c1f09e42c (patch) | |
| tree | 798c26ddb30c6791656b22a7c5f106ac56a439ed /challenge-029/dave-jacoby | |
| parent | fc8c3cbe03a665fdadf665ff518a0300b1b84264 (diff) | |
| download | perlweeklychallenge-club-d3ac4cea33e2d802775b8d5b13c2e87c1f09e42c.tar.gz perlweeklychallenge-club-d3ac4cea33e2d802775b8d5b13c2e87c1f09e42c.tar.bz2 perlweeklychallenge-club-d3ac4cea33e2d802775b8d5b13c2e87c1f09e42c.zip | |
removed misplaced files
Diffstat (limited to 'challenge-029/dave-jacoby')
| -rwxr-xr-x | challenge-029/dave-jacoby/ch-1.pl | 128 | ||||
| -rwxr-xr-x | challenge-029/dave-jacoby/ch-2.pl | 12 |
2 files changed, 0 insertions, 140 deletions
diff --git a/challenge-029/dave-jacoby/ch-1.pl b/challenge-029/dave-jacoby/ch-1.pl deleted file mode 100755 index 23d57ff463..0000000000 --- a/challenge-029/dave-jacoby/ch-1.pl +++ /dev/null @@ -1,128 +0,0 @@ -#!/usr/bin/env perl - -use strict; -use warnings; -use utf8; -use feature qw{ postderef say signatures state switch }; -no warnings - qw{ experimental::postderef experimental::smartmatch experimental::signatures }; - -# Task #1 -# Write a script to demonstrate brace expansion. For example, script -# would take command line argument -# Perl {Daily,Weekly,Monthly,Yearly} Challenge -# and should expand it and print like below: -# Perl Daily Challenge -# Perl Weekly Challenge -# Perl Monthly Challenge -# Perl Yearly Challenge - -# HT https://rosettacode.org/wiki/Brace_expansion#Perl - -use JSON; -my $json = JSON->new->pretty->canonical; - -my $argv = join ' ', @ARGV; -say $argv; -say '-' x length $argv; - -my @array = expand($argv); -say join "\n", @array; - -say '-' x length $argv; - -my @expand = brace_expand($argv); -say join "\n", @expand; - -say '-' x length $argv; - -sub expand ($input) { - my @stack = ( [ my $current = [''] ] ); - my @input = $input =~ /\G ((?:[^\\{,}]++ | \\(?:.|\z))++ | . )/gx; - for my $token (@input) { - if ( $token eq '{' ) { push @stack, ( [ $current = [''] ] ) } - elsif ( $token eq ',' && @stack > 1 ) { - push @{ $stack[-1] }, ( $current = [''] ); - } - elsif ( $token eq '}' && @stack > 1 ) { - my $group = pop @stack; - $current = $stack[-1][-1]; - - # handle the case of brace pairs without commas: - @{ $group->[0] } = map { "{$_}" } @{ $group->[0] } - if @$group == 1; - - @$current = map { - my $c = $_; - map { - map { $c . $_ } - @$_ - } @$group; - } @$current; - } - else { - $_ .= $token for @$current; - } - } - - while ( @stack > 1 ) { - my $right = pop @{ $stack[-1] }; - my $sep; - if ( @{ $stack[-1] } ) { $sep = ',' } - else { $sep = '{'; pop @stack } - $current = $stack[-1][-1]; - @$current = map { - my $c = $_; - map { $c . $sep . $_ } @$right; - } @$current; - } - - return @$current; -} - -sub brace_expand { - my $input = shift; - my @stack = ( [ my $current = [''] ] ); - - while ( $input =~ /\G ((?:[^\\{,}]++ | \\(?:.|\z))++ | . )/gx ) { - - if ( $1 eq '{' ) { - push @stack, [ $current = [''] ]; - } - elsif ( $1 eq ',' && @stack > 1 ) { - push @{ $stack[-1] }, ( $current = [''] ); - } - elsif ( $1 eq '}' && @stack > 1 ) { - my $group = pop @stack; - $current = $stack[-1][-1]; - - # handle the case of brace pairs without commas: - @{ $group->[0] } = map { "{$_}" } @{ $group->[0] } - if @$group == 1; - - @$current = map { - my $c = $_; - map { - map { $c . $_ } - @$_ - } @$group; - } @$current; - } - else { $_ .= $1 for @$current; } - } - - # handle the case of missing closing braces: - while ( @stack > 1 ) { - my $right = pop @{ $stack[-1] }; - my $sep; - if ( @{ $stack[-1] } ) { $sep = ',' } - else { $sep = '{'; pop @stack } - $current = $stack[-1][-1]; - @$current = map { - my $c = $_; - map { $c . $sep . $_ } @$right; - } @$current; - } - - return @$current; -} diff --git a/challenge-029/dave-jacoby/ch-2.pl b/challenge-029/dave-jacoby/ch-2.pl deleted file mode 100755 index a3c16ad815..0000000000 --- a/challenge-029/dave-jacoby/ch-2.pl +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env perl - -use strict; -use warnings; -use utf8; -use feature qw{ postderef say signatures state switch }; -no warnings - qw{ experimental::postderef experimental::smartmatch experimental::signatures }; - -# Task #2 -# Write a script to demonstrate calling a C function. -# It could be any user defined or standard C function.
\ No newline at end of file |
