Last active
July 19, 2020 13:51
-
-
Save LadyAleena/63b182e0230c1ca2ab59333de9402fff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub fancy_open { | |
my ($filename, $opt) = @_; | |
my $encoding = $opt->{'encoding'} // 'utf-8'; | |
open my $fh, "<:encoding($encoding)", $filename or die "Can't open $filename. $!"; | |
my @array; | |
my $before = $opt->{'before'} // ""; | |
my $after = $opt->{'after'} // ""; | |
while ( my $line = <$fh> ) { | |
chomp $line; | |
my $final_line = $before . $line . $after; | |
push @array, $final_line; | |
} | |
close($fh); | |
return @array; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment