From 595d3fb44c4f413902411f684f872d3f5e092f93 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Mon, 6 Nov 2023 07:43:20 -0800 Subject: [PATCH] simplify several split calls --- lib/Perl/Tidy/HtmlWriter.pm | 9 +++------ lib/Perl/Tidy/IOScalar.pm | 10 +--------- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/lib/Perl/Tidy/HtmlWriter.pm b/lib/Perl/Tidy/HtmlWriter.pm index 411046dd..43135281 100644 --- a/lib/Perl/Tidy/HtmlWriter.pm +++ b/lib/Perl/Tidy/HtmlWriter.pm @@ -861,8 +861,7 @@ sub pod_to_html { if ($toc_string) { $html_print->("
\n") if $rOpts->{'frames'}; $html_print->("

Code Index:

\n"); - ##my @toc = map { $_ .= "\n" } split /\n/, $toc_string; - my @toc_st = map { $_ . "\n" } split /\n/, $toc_string; + my @toc_st = split /^/, $toc_string; $html_print->(@toc_st); } $in_toc = EMPTY_STRING; @@ -886,8 +885,7 @@ sub pod_to_html { if ($toc_string) { $html_print->("
\n") if $rOpts->{'frames'}; $html_print->("

Code Index:

\n"); - ##my @toc = map { $_ .= "\n" } split /\n/, $toc_string; - my @toc_st = map { $_ . "\n" } split /\n/, $toc_string; + my @toc_st = split /^/, $toc_string; $html_print->(@toc_st); } $in_toc = EMPTY_STRING; @@ -1310,8 +1308,7 @@ HTML_END if ( $html_fh->can('close') ); if ( $rOpts->{'frames'} ) { - ##my @toc = map { $_ .= "\n" } split /\n/, ${$rtoc_string}; - my @toc = map { $_ . "\n" } split /\n/, ${$rtoc_string}; + my @toc = split /^/, ${$rtoc_string}; $self->make_frame( \@toc ); } return; diff --git a/lib/Perl/Tidy/IOScalar.pm b/lib/Perl/Tidy/IOScalar.pm index b8df588c..cd419e4e 100644 --- a/lib/Perl/Tidy/IOScalar.pm +++ b/lib/Perl/Tidy/IOScalar.pm @@ -64,17 +64,9 @@ EOM # Convert a scalar to an array. # This avoids looking for "\n" on each call to getline - # - # NOTES: The -1 count is needed to avoid loss of trailing blank lines - # (which might be important in a DATA section). my @array; if ( $rscalar && ${$rscalar} ) { - - #@array = map { $_ .= "\n" } split /\n/, ${$rscalar}, -1; - @array = map { $_ . "\n" } split /\n/, ${$rscalar}, -1; - - # remove possible extra blank line introduced with split - if ( @array && $array[-1] eq "\n" ) { pop @array } + @array = split /^/, ${$rscalar}; } my $i_next = 0; return bless [ \@array, $mode, $i_next ], $package; -- 2.39.5