Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Manually incrementing @ array during for

by johngg (Canon)
on Mar 16, 2020 at 16:48 UTC ( #11114355=note: print w/replies, xml ) Need Help??


in reply to Manually incrementing @ array during for

It might be simpler to do a first pass concatenating continuation lines via splice before your main processing.

johngg@shiraz:~/perl/Monks$ perl -Mstrict -Mwarnings -E ' open my $inFH, q{<}, \ <<__EOD__ or die $!; keyword1 data1 data2 data3 keyword2 data1 data2 data3 data4 data5 data6 keyword1 data1 data2 data3 data4 keyword3 data1 __EOD__ my @dataLines = <$inFH>; chomp @dataLines; close $inFH or die $!; for my $idx ( reverse 0 .. $#dataLines ) { next if $dataLines[ $idx ] =~ m{^keyword}; $dataLines[ $idx - 1 ] .= splice @dataLines, $idx, 1; } say for @dataLines;' keyword1 data1 data2 data3 keyword2 data1 data2 data3 data4 data5 data6 keyword1 data1 data2 data3 data4 keyword3 data1

I hope this is of interest.

Cheers,

JohnGG

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (2)
As of 2020-06-05 01:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?



    Results (35 votes). Check out past polls.

    Notices?