Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re^4: Manually incrementing @ array during for

by AnomalousMonk (Bishop)
on Mar 16, 2020 at 20:20 UTC ( #11114364=note: print w/replies, xml ) Need Help??

in reply to Re^3: Manually incrementing @ array during for
in thread Manually incrementing @ array during for

Note that the body of this while-loop is equally well suited to the original for-loop implementation. The array is not changed.

c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "my @ra = ( 'keyword1 data1 data2 data3', 'keyword2 data1 data2 data3', ' data4 data5', ' data6', 'keyword1 data1 data2 data3 data4', 'keyword3 data1', ); ;; my $rx_continuation = qr{ \A \s+ \w }xms; ;; my $current_line; LINE: for my $line (@ra) { if ($line =~ $rx_continuation) { $current_line .= $line; next LINE; } ;; _process($current_line) if $current_line; $current_line = $line; } ;; _process($current_line) if $current_line; ;; dd \@ra ;; ;; sub _process { print qq{'$_[0]' ->}, map qq{ '$_'}, split ' ', $_[0]; } " 'keyword1 data1 data2 data3' -> 'keyword1' 'data1' 'data2' 'data3' 'keyword2 data1 data2 data3 data4 data5 data6' -> 'keyword2' 'da +ta1' 'data2' 'data3' 'data4' 'data5' 'data6' 'keyword1 data1 data2 data3 data4' -> 'keyword1' 'data1' 'data2' 'data +3' 'data4' 'keyword3 data1' -> 'keyword3' 'data1' [ "keyword1 data1 data2 data3", "keyword2 data1 data2 data3", " data4 data5", " data6", "keyword1 data1 data2 data3 data4", "keyword3 data1", ]

Give a man a fish:  <%-{-{-{-<

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11114364]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2020-05-27 07:20 GMT
Find Nodes?
    Voting Booth?
    If programming languages were movie genres, Perl would be:

    Results (153 votes). Check out past polls.