Date: Thu, 27 Sep 2001 14:56:52 +0200 From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= Subject: Re: Push into an array Message-Id: <5286rtscp25cql461vr98h10j68cvdskga@4ax.com> On Thu, 27 Sep 2001, "Blnukem" wrote: >How do I get this code to "push" $I into the @items array. Everything I >tried I get an error. This code only gives me the last count of $i "9". Yes. Did you expect something else? >print "Content-type: text/html\n\n"; >for ($i = 0; $i < 10; $i +=1 ){ > > >@items = "$i" This assign a string containing a number to the array. If you want to add data to an existing array, use unshift, push, splice or array operations. >} >print "@items " ; Well, there is only one element to print in there. Try this: #!/usr/bin/perl -w # important: turn on warnings and strict! use strict; print "Content-type: text/html\n\n"; # declare the variables you use! my @items; for( my $i = 0; $i < 10; $i++ ){ push @items, $i; } print "Number of items in array: ", scalar(@items), "\n"; print "Index of last element in array: $#items\n"; print "Elements in array: ", join(', ', @items ), "\n"; __END__ HTH, -- use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord} split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('. '"`P