There are actually 7 fields total. The name Avg does not mean anything. I
just copied and pasted an old code to save some time in editing while
testing this functionality. Also "i" is a typo. should have put all the
seven fields. So this is how it should look like

 abc   123  33545  789  52635 87236  7828

I tried with, after removing "i" 

" split ' ' "   and " split (/\s+/,$Avg) "  as well, but no success

Thanks


-----Original Message-----
From: Charles K. Clarkson [mailto:[EMAIL PROTECTED] 
Sent: Monday, June 28, 2004 11:44 AM
To: 'Naser Ali'; [EMAIL PROTECTED]
Subject: RE: string seperated by multiple spaces


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





Reply via email to