From: Naser Ali <mailto:[EMAIL PROTECTED]> wrote:
: Hello all, : : I have a line of text and numbers each seperated by : multiple or single spaces looks like this : : abc 123 33545 789 : : I wanted to split the above line and store each : column value in a specific variable and later : print, use strict; use warnings; my $foo = 'abc 123 33545 789'; my @fields = split ' ', $foo; print join ', ', @fields; __END__ : Below is the code I am using but it's not working : as I desire, : : $Avg=$first[$i]; : chomp($Avg); : ($label,$TD,$YT,$M,$L,$Y,$W)= split (/i\s*/,$Avg); What is the 'i' for? The example above doesn't have any 'i's in it. What is really in $Avg? The example above only had 4 fields. This seems to be looking for 7 fields. Which is it 4 or 7? : print "$label,$TD,$YT,$M,$L,$Y,$W\n"; : : I used "\s*" in split, so I do not have worry about : counting the spaces or tabs between each field Read perlfunc 'split'. Splitting on white space is covered there. '\s+' would match on more than one space. '\s*' matches on zero or more spaces. Most of the time I find " split ' ' " does what I need. HTH, Charles K. Clarkson -- Mobile Homes Specialist 254 968-8328 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>