in reply to split on every n lines

Can I have some simple solution. Something like this ? Its not working though. Dont know why

#!/usr/bin/perl -w use strict; use warnings; open(my $fh, '<', '/tmp/list') or die "Unable to open file, $!"; my @entire_file=<$fh>; for my $i (0..$#entire_file) { my @group; push @group,$entire_file[$i] until ( $i % 5 == 0 ); `tool.pl @group`; }

Replies are listed 'Best First'.
Re^2: split on every n lines
by hbm (Hermit) on Apr 11, 2014 at 01:52 UTC
    #!/usr/bin/perl use strict; use warnings; open my $fh, '<', 'list.txt' or die $!; chomp(my @hosts = <$fh>); close $fh; while (my @five = splice @hosts, 0, 5) { print qq{command @five\n}; } # prints: command host1 host2 host3 host4 host5 command host6 host7 host8 host9 host10 command host11 host12
Re^2: split on every n lines
by monsoon (Pilgrim) on Apr 10, 2014 at 20:48 UTC
    'until' starts an infinite loop when $i == 1