Change
($record, $customer, $location, $plan, @items) = split(/\^/, $_);
                                                        ^^
To
($record, $customer, $location, $plan, @items) = split(/[\^\s]+/, $_);
                                                         ^^^^
Split buy default works on $_, so you can also exclude ', $_' if you wish,
shortening to:
                                               = split /[\^\s]+/
The trailing '+' is unnecessary but it will suck up consecutive white spaces
and and carets.

-----Original Message-----
From: Ho, Tony [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, April 23, 2002 5:07 AM
To: '[EMAIL PROTECTED]'
Subject: Assigning values from files into an aray


Hi guys
I was wondering if you could help me.
 
I have the following row of data in one file:
 
405^100^200^A^B C D E
 
I have the following fragment of code that reads the data row:
 
while (<FILE_OPENED>) {
          $number_of_elements= 0;          
          chop;
          ($record, $customer, $location, $plan, @items) = split(/\^/, $_);
          $number_of_elements= $#items +  1;
          print "number_of_elements: $number_of_elements\n";
}
 
At the moment, the program prints out the value of "number_of_elements" to
be 1.
However "number_of_elements" should print out 4 because there are 4 values
(i.e. B, C, D, E)
 
Any ideas where I am going wrong ?
Any advice would be greatly appreciated.
 
Thanks in advance
Tony

 
 
 
 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to