aocinit

Perl utility to initialize directories and files for the Advent of Code
git clone git://git.samirparikh.com/aocinit
Log | Files | Refs | README

commit 0a2a047335c9536c70a828306f46b27589db16c3
parent e4e9ef3b70759a9bb2bc6cc126bfc8b1512217a8
Author: Samir Parikh <noreply@samirparikh.com>
Date:   Fri, 16 Dec 2022 20:14:14 +0000

get creation of boilerplate code to work

Diffstat:
Maocinit | 26+++++++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/aocinit b/aocinit @@ -6,6 +6,7 @@ use strict; use warnings; +use autodie; use v5.32; use Term::ANSIColor; use Scalar::Util qw(looks_like_number); @@ -62,9 +63,32 @@ sub create_day_subdirectory { } } +sub create_boilerplate { + my ( $year, $day ) = @_; + say "received $year and $day"; + ( my $boilerplate = qq[ + #!/usr/local/bin/perl + # day 20$year-$day + + use strict; + use warnings; + use v5.32; + + \@ARGV = "input" unless \@ARGV; + chomp( my \$input = do { local \$/; <> } ); + ] ) =~ s/^ {8}//mg; + $boilerplate =~ s/\A\n//; + return $boilerplate; +} + my ( $year, $day ) = process_arguments( \@ARGV ); my $year_directory = "$HOME/$PATH_FROM_HOME/$DIR_PREFIX$year"; -my $day_subdir = catfile ( $year_directory, "day" . $day ); +my $day_subdir = catfile( $year_directory, "day" . $day ); +my $day_file = catfile( $day_subdir, "day". $day . ".pl" ); +my $boilerplate = create_boilerplate( $year, $day ); create_year_directory( $year_directory ); create_day_subdirectory( $day_subdir ); +open my $bp_file, '>', $day_file; +say $bp_file $boilerplate; +close $bp_file;