Thanks a lot!! This is exactly what I needed! Emanuele On Wed, Jul 22, 2009 at 15:04, Wagner, David --- Senior Programmer Analyst --- CFS <david.wag...@fedex.com> wrote:
> > -----Original Message----- > > From: Emanuele Osimo [mailto:e.os...@gmail.com] > > Sent: Wednesday, July 22, 2009 15:47 > > To: beginners perl ml > > Subject: Reading a list of numbers into an array > > > > Hello there, I'd like to read a file thet is a list of numbers like: > > 3084 > > 4855 > > 2904 > > making each line (each number) one of the elements of the > > array. I've tried > > foreach my $line (<FILEHANDLE>){ push (@array, $line) } > > but then printing the array just gives me the last number, in > > this case > > "2904". > > What's wrong? > > > Here is a simple script based on what you gave here and it > works: > #!/usr/bin/perl > > use strict; > use warnings; > my @array = (); > > foreach (<DATA>){ > chomp; > > push (@array, $_); > > } > foreach ( @array ) { > print $_ . "\n"; > } > __DATA__ > 3084 > 4855 > 2904 > > Output: > 3084 > 4855 > 2904 > > Thanks > > Emanuele > > >