[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

: : "Charles K. Clarkson" <[EMAIL PROTECTED]> wrote
:
: All,
:
: Could you please explain line by line what this code
: is doing below from Charles?

    Sorry it took so long. I must have missed this one.


: : use strict;
: : use warnings;
: :
: : use Tie::File;
: : use Array::Dissect qw( reform );

    Array::Dissect is a module that provides
a function named reform(). It is used to change
single dimesioned arrays into two dimensional
arrays.

    For your report, a two dimensional array
would be far easier to print than a single
dimensioned array.

    An example:

use Array::Dissect qw( reform );

my @foo = ( 1 .. 40 );

printf '%02d ' x 40, @foo;

print "\n\n\nThe reformed array:\n";

foreach my $report_line ( reform( 5, @foo ) ) {
    printf '%02d ' x 5, @$report_line;
    print "\n";
}

__END__

: : tie my @content, 'Tie::File', 'eject 0,0,0 '
: :     or die qw(Cannot open "eject 0,0,0 ": $!);

    This (hopefully) ties your file to an array.
Anything done to the array will be done to the
underlying file.

     'eject 0,0,0 ' is a mistake. I misunderstood
what you were opening. It should be this. Assuming
$ejectapes holds the filename you are reading.

    NOTE: don't change the array values. It *will*
change the values in the file itself.

tie my @content, 'Tie::File', $ejectapes
    or die qw(Cannot open "$ejectapes": $!);


    BTW, why are your ejecting apes? And where
do they go after you eject them?


: : my $last_index = @content > 40 ? 39 : $#content;

    Since you want to limit the array size to 40,
and since you didn't specify whether there might
be less than 40 lines in the file, this statement
limits the last index of the tied array (@content).


: : print join( ' ', @$_ ), "\n"
: :     foreach reform( 8, @content[ 0 .. $last_index ] );

    This is a shortcut for:

foreach $row ( reform( 8, @content[ 0 .. $last_index ] ) ) {
    print join( ' ', @$row ), "\n";
}

    A two dimensional array in perl is an Array of
Array References. In this case $row is a reference
to each line of the reformed array. @$row is the
array and we print that array with the print
statement.


: 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

    Er, no, that would be 8 lines of 5, not 5 lines
of 8. You originally asked for 5 lines of 8. If
that is what you want change the last line above
to this.

print join( ' ', @$_ ), "\n"
    foreach reform( 5, @content[ 0 .. $last_index ] );


: 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 !  :)


Perl or perl -- never PERL. :)


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


PS  The ape comments were a small joke. Or as
Pocahontas might say a Minnehaha. If you don't
have a sense of humor you might want to killfile
my future posts. It only gets worse from here. :)







-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to