in reply to Can't use string ("...") as an ARRAY ref while "strict refs" in use at x.pl line ...
Code rewrite
use warnings; use strict; use Data::Dumper; my @a = (1..1284); my $chunkedRef = chunky(@a); sub chunky { #for chunks (chunks = 100 blocks of passed -in array) + + my %master; for(0..int @_/100) { # create an array for each 100 elements and add it to the has +h + push @{$master{$_+1 . ' key'}},@a[$_*100..$_*100+100]; } return \%master; } print Dumper %$chunkedRef; 1;
Celebrate Intellectual Diversity
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Can't use string ("...") as an ARRAY ref while "strict refs" in use at x.pl line ...
by LanX (Saint) on Jun 09, 2014 at 19:22 UTC | |
Re^2: Can't use string ("...") as an ARRAY ref while "strict refs" in use at x.pl line ...
by AnomalousMonk (Archbishop) on Jun 09, 2014 at 18:49 UTC |
In Section
Seekers of Perl Wisdom