To access each field, you just have to access theindivudual array elements
open FILE, $file or die "Cannot open file: $!\n";
while (<FILE>) {
my @list = split; # splits using a space as delimiter
for (0..(@list-1)) { # goes from the first field position to
the last
print "@list[$_] "; # This is the variable for the current field
read in the array
}
print "\n";
}
let's say your file has in it:
=====
hello world
foo bar
=====
The script will return:
hello world
foo bar
(the exact same output since there is no modification done with each word)
Hope it's what you're looking for
Etienne
"José A. Ferrer" wrote:
Thank you.
It works but I need each field in one scalar variable.
T.I.A.
open the file,while (<FILE>) {
my @list = split(/ /, $_);
..do something with the list..
}This way you have to make the appropriate work inside each loop in the while
because @list gets the new line value each time..Etienne
"José A. Ferrer" wrote:
> Please,
>
> I have a text file separated with one or more whitespaces. I need to
> extract each line to scalar variables everything but whitespaces. How can
> it be done in perl ?
>
> TIA.
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
***************************************
Jose A. Ferrer, [EMAIL PROTECTED]
TOTWARE NOVELDA, S.L.
Ntra. Sra. de la Fe, 24 bajos
03660 NOVELDA (Alicante) SPAIN
Tel: +34 965600198 , Fax: +34 965606245
http://www.totware.com
http://www.marblenet.es
***************************************