Hello,
Ok, I have it working but I am not sure why:
--snip-- sub printlist { my $arrayref = [EMAIL PROTECTED]; ## create a reference to my passed array my $max; for(my $i=0;$i <= @$arrayref; $i++){ ## Dereference the passed array to find number of elements @$arrayref print "\t\t\t\t\t";
if ( (@$arrayref - $i) >= 10 ) { $max = 10; } else { $max = @$arrayref - $i; }
for(my $n=0; $n <= $max; $n++) { print "$arrayref->[$i]\t"; $n++; $i++; } print "\n"; } }
&printlist(@servers);
--snip--
Michael
Michael Gale wrote:
Hello,
I am trying to pass an array by reference since it could become very large. The function should take the array and print it out but only 10 elements per line.
#!/usr/bin/perl -w
use strict; use warnings;
use DBI;
......
sub printlist {
my $arrayref = @_; my $max = $arrayref; my $nmax; for(my $i = 0; $i <= $max; $i++) { print "\t\t\t\t\t";
if ( ($max - $i) >= 10 ) { $nmax = 10; } else { $nmax = $max - $i; }
for(my $n = 0; $n <= $nmax; $n++) { print "$arrayref->[$i]\t"; # line 209 $n++; $i++; } print "\n"; }
}
......
&printlist([EMAIL PROTECTED]);
But I am receiving the following error:
Can't use string ("1") as an ARRAY ref while "strict refs" in use at ./mysql-watch.pl line 209.
Does anybody know why ?
Thanks
Michael
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>