All, Could you please explain line by line what this code is doing below from Charles? I think I understand most of it but just to make sure. All I want to do is set up a maximum 40 element array with each element as an E string. From there only print 5 elements per line then "\n" then elements 6-10... etc. This would be 5 lines of 8 never more, always less Here is my visual:
1 2 3 4 5 6 7 8 9 10 11 12 element 1 and all others would be Exxxxx. This cannot be that hard, but since I am new to the code it is hard. KSH is much easier, but I want to learn PERL ! :) Here is my current code. I attempted to use Tie::File and Array::Dissect but was getting bad results. My FileHandle FILE has the E strings in it with newlines and FILEOUT has the data from FILE with eject 0,0,0 in front like so: eject 0,0,0 Exxxx Exxxx Exxxx etc. with no new lines thanks to chomp. use strict; use warnings; use MIME::Lite; ## Declare variables, set scaler ^I(rw to same file), init array, create filehandles local $ENV{'PATH'} = "/usr/epoch/bin:/usr/epoch/EB/bin:/bin:/usr/bin"; my @ejectapes = "/usr/local/bin/perld/derektapes"; ($^I, @ARGV) = ('.bak', $ejectapes); open (FILE, "<@ejectapes") or die "cannot open file: $!\n"; open (FILEOUT, ">/tmp/ejects.out$$") or die "failed to open eject.out: $!\n"; my @ejects = "/tmp/ejects.out$$"; print FILEOUT "eject 0,0,0 "; my $count = `wc -l <@ejectapes`; if ($count <= 40 ) { while(<FILE>) { chomp $_; print FILEOUT "$_ "; } close (FILEOUT); print "\n"; print "Number of lines are: $count \n"; # application calls as below #`evmeject -r $_`; #`evmeject -l offsite_0 -b$_`; } else { my $msg = MIME::Lite->new( From => 'EDM01 <[EMAIL PROTECTED]>', To => 'Derek Smith <[EMAIL PROTECTED]>', Subject => "Eject list is greater than 40", Data => "@ejectapes" ); $msg->send; } close (FILE); Thank you, derek "Charles K. Clarkson" <[EMAIL PROTECTED]> 07/01/2004 05:12 PM To: <[EMAIL PROTECTED]>, <[EMAIL PROTECTED]> cc: Subject: RE: printing 10 scalers/elements [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: : I am trying to figure out how to print 8 scalers/elements : then \n, then 5 more lines of 8 or less for a max total : of 40 Here is my code: : : print FILEOUT "eject 0,0,0 "; : my $count = `wc -l <$ejectapes`; [snip] How about: use strict; use warnings; use Tie::File; use Array::Dissect qw( reform ); tie my @content, 'Tie::File', 'eject 0,0,0 ' or die qw(Cannot open "eject 0,0,0 ": $!); my $last_index = @content > 40 ? 39 : $#content; print join( ' ', @$_ ), "\n" foreach reform( 8, @content[ 0 .. $last_index ] ); HTH, Charles K. Clarkson -- Mobile Homes Specialist 254 968-8328