From: Steve Hancock <perltidy@users.sourceforge.net>
Date: Mon, 6 Nov 2023 15:43:20 +0000 (-0800)
Subject: simplify several split calls
X-Git-Tag: 20230912.06~30
X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=595d3fb44c4f413902411f684f872d3f5e092f93;p=perltidy.git

simplify several split calls
---

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->("<hr />\n") if $rOpts->{'frames'};
                 $html_print->("<h2>Code Index:</h2>\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->("<hr />\n") if $rOpts->{'frames'};
                     $html_print->("<h2>Code Index:</h2>\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;