Jim Gibson wrote: > On 5/13/09 Wed May 13, 2009 4:48 PM, "Steve Bertrand" <st...@ibctech.ca> > scribbled: > >> Hi all, >> >> I'm trying to push a scalar onto an array. The array I'm trying to >> push() to is the first element of another array. I can't figure out what >> I'm missing. It would be appreciated if someone could point me in the >> right direction. >> >> if (-e $data_file) { >> >> $graph_data = retrieve $data_file; >> >> $x_axis = $graph_data->[0][0]; >> $x_axis++; >> >> # start pushing the next days data into the aoa >> push ($graph_data->[0], ($x_axis)); >> >> store $graph_data, $data_file; >> } > > Your program shouldn't even compile. I get: > > "Type of arg 1 to push must be array (not array element) at ..."
That is where I was at as well. I just wanted to provide a code snippet that provided proper context. > The first argument of push should be an array, not a scalar (even if that > scalar is a reference to an array). > > push( @{$graph_data->[0]}, $x_axis ); I'll have to do a bit of reading, because I can't remember why the braces are important here. All I know is that it works ;) > If you are having more trouble, use the Data::Dumper module to inspect the > contents of your AoA: I was using Dumper, but I was getting results that I didn't expect, and I didn't know why. However, with your help, things are looking good. I'm now on track to start pushing onto all of the arrays: pearl# ./simscan-stats.pl yesterday ***5 $VAR1 = [ [ 1, '2', '3', '4', '5' ], [ 854 ], [ 388 ], [ 287 ], [ 511 ], [ 146 ], [ 365 ] ]; Thanks! Steve
smime.p7s
Description: S/MIME Cryptographic Signature